Npm global install failing for terraform

Hi,
I was setting up the Gitlab CI. One of the job require terraform. I tried installing it globally using npm, but this step if failing. Please find the error log:

$ npm install -g terraform
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated classifier@0.1.0: Package no longer supported. Contact support@npmjs.com for more info.
npm WARN notice [SECURITY] cli has the following vulnerability: 1 low. Go here for more details: https://nodesecurity.io/advisories?search=cli&version=0.11.3 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm WARN notice [SECURITY] tunnel-agent has the following vulnerability: 1 moderate. Go here for more details: https://nodesecurity.io/advisories?search=tunnel-agent&version=0.4.3 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm WARN notice [SECURITY] lodash has the following vulnerability: 1 low. Go here for more details: https://nodesecurity.io/advisories?search=lodash&version=4.17.4 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm WARN notice [SECURITY] hoek has the following vulnerability: 1 moderate. Go here for more details: https://nodesecurity.io/advisories?search=hoek&version=2.16.3 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.

> node-sass@4.9.0 install /usr/local/lib/node_modules/terraform/node_modules/node-sass
> node scripts/install.js

Unable to save binary /usr/local/lib/node_modules/terraform/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/terraform/node_modules/node-sass/vendor'
    at Object.fs.mkdirSync (fs.js:885:18)
    at sync (/usr/local/lib/node_modules/terraform/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/usr/local/lib/node_modules/terraform/node_modules/mkdirp/index.js:77:24)
    at checkAndDownloadBinary (/usr/local/lib/node_modules/terraform/node_modules/node-sass/scripts/install.js:114:11)
    at Object.<anonymous> (/usr/local/lib/node_modules/terraform/node_modules/node-sass/scripts/install.js:157:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/usr/local/lib/node_modules/terraform/node_modules/node-sass/vendor' }

> node-sass@4.9.0 postinstall /usr/local/lib/node_modules/terraform/node_modules/node-sass
> node scripts/build.js

Kindly let me know if something is missing.

Releveant configuration block:

.publish_ci_workshops_storage_api: &publish_ci_workshops_storage_api
  stage: publish_ci
  before_script:
    - apt update
    - apt install -y python python-dev python-setuptools
    - easy_install pip
    - pip install awscli
    - npm install -g terraform
  script:
    - aws s3 cp s3://[s3-bucket]/$ENV/config.json ./config.json
    - ./node_modules/.bin/gulp circle-publish-ci
  tags:
    - docker
    - phoenix

publish_ci_development:
  <<: *publish_ci_workshops_storage_api
  variables:
    ENV: dev
  except:
    - /^release\/[0-9]+\.[0-9]+\.[0-9]+$/
    - tags

Regards,
Dheeraj.

Hi Dheeraj
You may have to try sudo npm install -g terraform

Hi Balaji,
Thanks.
Tried that. But then it doesn’t recognises ‘sudo’. I believe its running with sudo privileges already.

May be you can try to give write permission for the folder /usr/local/lib/node_modules for the user who execute that command.