'"g++: error: unrecognized command line option ‘-std=gnu++14’" with gcc version 9.3.0

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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ATorras