Netlify CLI fails to install

I am trying to install the Netlify CLI via sudo npm install netlify-cli -g on my mac running MacOS Big Sur 11.2.3 and it throws this npm error :

sudo npm install netlify-cli -g                                    127 ✘
Password:

npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated rollup-plugin-inject@3.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.

> yarn@1.22.10 preinstall /usr/local/lib/node_modules/netlify-cli/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)

/usr/local/bin/netlify -> /usr/local/lib/node_modules/netlify-cli/bin/run
/usr/local/bin/ntl -> /usr/local/lib/node_modules/netlify-cli/bin/run

> esbuild@0.8.57 postinstall /usr/local/lib/node_modules/netlify-cli/node_modules/esbuild
> node install.js

Trying to install "esbuild-darwin-64" using npm
Failed to install "esbuild-darwin-64" using npm: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/esbuild-lcsaklv44g'
Trying to download "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.8.57.tgz"
/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:178
      throw e;
      ^

Error: EACCES: permission denied, open '/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/bin/esbuild'
    at Object.openSync (fs.js:476:3)
    at Object.writeFileSync (fs.js:1467:35)
    at installBinaryFromPackage (/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:42:6)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  errno: -13,
  syscall: 'open',
  code: 'EACCES',
  path: '/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/bin/esbuild'
}
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @netlify/traffic-mesh-agent-win32-x64@^0.27.10 (node_modules/netlify-cli/node_modules/@netlify/traffic-mesh-agent/node_modules/@netlify/traffic-mesh-agent-win32-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @netlify/traffic-mesh-agent-win32-x64@0.27.10: wanted {"os":"win32","arch":"x64"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @netlify/traffic-mesh-agent-linux-x64@^0.27.10 (node_modules/netlify-cli/node_modules/@netlify/traffic-mesh-agent/node_modules/@netlify/traffic-mesh-agent-linux-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @netlify/traffic-mesh-agent-linux-x64@0.27.10: wanted {"os":"linux","arch":"x64"} (current: {"os":"darwin","arch":"x64"})
npm WARN @octokit/plugin-request-log@1.0.3 requires a peer of @octokit/core@>=3 but none is installed. You must install peer dependencies yourself.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! esbuild@0.8.57 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the esbuild@0.8.57 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/nino-p/.npm/_logs/2021-03-18T15_03_23_690Z-debug.log

I tried installing it without the sudo comand and it failed, I tried one more time without sudo and it actually installed successfully. Weird stuff, but it worked :wink:

Hey there, @DesignedByNino

Thank you so much for sharing your solution, I appreciate it! This is always beneficial for future Forums members who may encounter something similar.

1 Like

Did not work for me. Even tried older netlify-cli and removing ~/.npm.

What did work for me:

  • Solution A: sudo npm install netlify-cli -g --unsafe-perm
  • Solution B: sudo chmod o+w /opt/local/lib/node_modulesand then install without sudo. But everything belongs to the current user now.

Strange thing as I did not change anything on my system.

6 Likes

Thanks for sharing this! People like you make Netlify Forums great :grinning: :netliheart:

1 Like

Thanks for sharing here, i just applied your solution B and it worked for me.

but small change in path:

in your case: sudo chmod o+w /opt/local/lib/node_modules
in my case: sudo chmod o+w /usr/lib/node_modules

:grinning: :+1:

Hi, @mshekh. I must point out that installing netlify-cli using sudo is neither required nor recommended.

2 Likes

Solution A worked for me everyone is different