User Tools

Using npm on Gentoo

Quite similarly to the issue with pip, direct installation of NodeJS packages via npm poses some issues since you don't really want to mess up your system by installing out of tree packages. Everything should be managed by portage, but hey, there are literally thousand of packages that you might find usefull to install via npm.

The solution is simple. First of all, ensure that you have net-libs/nodejs installed with the npm use flag:

echo "net-libs/nodejs npm" >> /etc/portage/package.use/nodejs
emerge -v net-libs/nodejs

this will ensure you have the npm command available, but you do not want to run it as user root, instead the best practice is to install packages only as non-root users.

To do so, you need to run, as the non-root user, the following command:

su - my_non_root_user
npm config set prefix .npm_install

Add this to your ~/.bashrc:

export PATH=$PATH:~/.npm_install/bin

At this point, you will be able to install packages with a command like:

npm install mypackage -g

And it will work!

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information