3

I have the CentOS Linux release 7.9.2009 (Core) running in the VirtualBox, which was build by the Vagrant 2.2.19 and the Ansible 2.9.25 installed all the depedencies. On the machine there are installed:

gcc 9.3.0
python 3.6.8
node.js 16.13.1
npm 8.1.2

When the ansible executes the npm install I get errored with the g++: error: unrecognized command line option ‘-std=gnu++14’. I saw many questions here on the Stackoverflow, where the answers told me to upgrade the gcc to version >= 4.9. But I already have that and I'm still getting an error.

However, there is a workaround, which allows me to run the npm install:

sudo yum install -y centos-release-scl
sudo yum install -y devtoolset-9-gcc*
scl enable devtoolset-9 bash
npm install

but I have to run this manually, after I'm logged into the CentOS by the vagrant ssh. I'm not satisfied with this workaround because it is manual and the npm istall must be run programatically, hence it doesn't solve my problem.

I have tried to execute the npm install inside the scl from the ansible playbook.yml:

- name: Install centos-release-scl
  shell: yum install -y centos-release-scl
  become: yes

- name: Install devtoolset-9
  shell: yum install -y devtoolset-9-gcc*
  become: yes

- name: install packages based on package.json
  shell: |            
    scl enable devtoolset-9 bash
    npm install 
  become: yes

but it didn't work.

Is there a way how can I run the npm install programatically by the ansible without getting error?

marsielko
  • 99
  • 2
  • 6
  • The "devtoolset-9-gcc-c++" (g++) is using the gcc-4.8 version `/usr/lib64/libstdc++.so.6` , and C++14 features are not all included in gcc until version 5.0 https://gcc.gnu.org/projects/cxx-status.html ...... Other extra gcc-c++ https://stackoverflow.com/questions/47175706/how-to-install-gcc-4-9-2-on-rhel-7-4/47189915#47189915 – Knud Larsen Jan 13 '22 at 13:35
  • @KnudLarsen Thank you for you answer, but as I said, the "devtoolset-9" is not an option for me, so I have upgraded the gcc by compiling it from source as its described in here: https://www.cyberithub.com/install-gcc-and-c-compiler/ but I have installed the version 11.2. The `gcc -v` and `g++ -v` both returned version 11.2 but the `cc -v` returned 4.8. I assume the nody-gyp is still using the 4.8 version, hence the error. I must find a way how to tell the node-gyp to use newer version. – marsielko Jan 20 '22 at 10:32
  • The system compiler **gcc-4.8.5** : `/usr/bin/cc` is a symlink to `/usr/bin/gcc` . ... Solution: Delete or rename the link. Then create a new link cc -> gcc version 11.2 . – Knud Larsen Jan 20 '22 at 13:25

2 Answers2

2

You can stick with gcc 4.8.5 but downgrading to NodeJS 14 (as pointed out in https://github.com/systemd/node-sd-notify/issues/29#issuecomment-1040909033).

Note: You can download NodeJS 14 at https://github.com/nodesource/distributions/blob/master/README.md#enterprise-linux-based-distributions

ATorras
  • 4,073
  • 2
  • 32
  • 39
2

For CentOS run this.

yum install gcc-c++

Then Install cmake.

yum install cmake

Then run.

yum install centos-release-scl

Install devtoolset.

yum install devtoolset-8-gcc devtoolset-8-gcc-c++

Enable devtoolset.

scl enable devtoolset-8 -- bash
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Asif Uddin
  • 31
  • 2