Search code examples
asp.net-coreubuntunpmyeomanubuntu-20.04

How can i install yeoman command line tool on ubuntu 20.04.1 LTS?


I tried installing yeoman command line tool in Ubuntu 20.04.1 LTS for ASP.NET Core web application development. After typing npm install -g yo in terminal, i got an error.

Description of error is provided below.

npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: cross-spawn no longer requires a build toolchain, use it instead
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN checkPermissions Missing write access to /usr/local/lib
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/shashankshekhar/.npm/_logs/2020-12-21T11_02_14_859Z-debug.log```

Solution

  • The issue of EACCES errors on global module installation is so common that npm has an entire web page dedicated to solving just this issue.

    Since you are installing yeoman, I imagine this is a development machine. In that case, your best bet is likely to install node/npm with a package manager like nvm.

    One thing you don't want to do but that people will often suggest is running the npm command with sudo. People recommend this because it's easy. But if you do that, all the lifecycle scripts (e.g., postinstall) of the dependencies of whatever you are installing will also be run as root. That's potentially a lot of untrusted code running as root.