Can't install netlify-cli on Ubuntu 20.04

Hello i had netlify-cli installed, version 3.5.0. When running the ntl serve command i was prompted to update the netlify-cli package to the latest 3.7.1 version.
I run command sudo npm i -g netlify-cli and not only it failed to update the package, but seems to have deleted the old one…
This is the output:

catta@catta-pc:~/lemurweb/lemur-business$ sudo npm i -g netlify-cli
[sudo] password di catta: 
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#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/ntl -> /usr/local/lib/node_modules/netlify-cli/bin/run
/usr/local/bin/netlify -> /usr/local/lib/node_modules/netlify-cli/bin/run

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

Trying to install "esbuild-linux-64" using npm
Failed to install "esbuild-linux-64" using npm: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/esbuild-i2bpt3bbadl'
Trying to download "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.8.49.tgz"
/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:204
      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 /usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:66:8
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:6:24)
    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: fsevents@~2.3.1 (node_modules/netlify-cli/node_modules/rollup/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
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":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @netlify/traffic-mesh-agent-darwin-x64@^0.27.10 (node_modules/netlify-cli/node_modules/@netlify/traffic-mesh-agent/node_modules/@netlify/traffic-mesh-agent-darwin-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @netlify/traffic-mesh-agent-darwin-x64@0.27.10: wanted {"os":"darwin","arch":"x64"} (current: {"os":"linux","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.49 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the esbuild@0.8.49 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!     /root/.npm/_logs/2021-02-19T10_13_32_007Z-debug.log

So seems to be a permission issue but i run the command with sudo.

Also, here are npm and node version:

catta@catta-pc:~$ node --version
v14.15.4
catta@catta-pc:~$ npm --version
6.14.10

Can someone help me with this?

1 Like

I have this exact same problem. Even logged in as root and go the same error as you.

Hi, @lemurweb-dev. First, it should be not required to run sudo to install the Netlify CLI tool. However, when using sudo with npm you often need to add a --unsafe-perm=true option like so:

sudo npm install -g --unsafe-perm=true netlify-cli

So, this is unrelated to the netlify-cli package is is due to installed esbuild-linux-64 using sudo.

Again, though, I would usually ask you to reconsider using sudo with npm in the first place as this isn’t something that is usually required.

If there are other questions or concerns, please let us know.

1 Like