NPM Install Global
When you are on a linux system and you want to run npm i -g <package>
, it is not unlikely that you’ll need root access since the packages by default wants to be installed to /usr/...
. Now, having to run sudo
every time you want to install some global node package feels wrong. So what can you do?
Well, I found this post on stackoverflow which was great. The second answer highlighted the process in two simple steps:
npm config set prefix ~/.local
- set the path to include
~/.local/bin
.
What’s so nice with this is that it plays well into the convention of having a ~/.local/bin
folder where you can put your own small play executables and scripts that you want globally accessible.