Is common have packages that works globally, they make the work more easy in some ways, provide functionalities, et al..
The difference in npm packages that are installed globally and locally is that you will setup a package like a program avaliable by a CLI(Command Line Interface)¹, this require permissions to write in some directories that the npm normally don’t has.
When you try install some globally package(using the -g):
npm install -g <package>
You can face errors and warnings like this:
npm WARN checkPermissions Missing write access to /usr/lib/node_modules npm ERR! path /usr/lib/node_modules npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall access npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules' npm ERR! { [Error: EACCES: permission denied, access '/usr/lib/node_modules'] npm ERR! stack: npm ERR! 'Error: EACCES: permission denied, access \'/usr/lib/node_modules\'', npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/usr/lib/node_modules' } 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 (though this is not recommended). npm ERR! A complete log of this run can be found in:
This is a EACESS error that can be fix by creating a directory for global installations, setting npm to config the directory and add the npm-global/bin to the path of OS(Operating System).
mkdir ~/.npm-global npm config set prefix '~/.npm-global' export PATH=~/.npm-global/bin:$PATH ### Add this to the end of the file ~/.profile source ~/.profile
This can be found in: https://docs.npmjs.com/getting-started/fixing-npm-permissions.
Don’t use sudo to install packages globally, this is a unsafe choice because npm install can run arbitrary scripts, you can get more EACESS errors later, locally you are creating a directory that only can be managed with sudo permissions, don’t make this.
- This can be conceptually wrong
Thanks a lot. It really helped
Didn’t work. It says no such file or directory. How do I create a directory?
You can try use: ~/.bashrc, ~/.bash_profile, ~/.bash_login or create the file ~/.profile.
And remember to change the source to the file that you are setting the environment variable.
Thank u very much, it fixed my problem!
Thanks broooooo thanks lifesaver
It doesnt work for me, I keep having this error: -bash: /Users/lucia/.profile: No such file or directory. HELP Please
You can try use: ~/.bashrc, ~/.bash_profile, ~/.bash_login or create the file ~/.profile.
And remember to change the source to the file that you are setting the environment variable.
this works!
i had gone through many post on internet but you post solved my errors !
thank you so much.
wow!!! i almost gave up trying everything and nothing worked thank you for this !! 🙂
thanks it’s solved the issue.
thanks, solved my problem in Fedora 31.