Reputation:
I've installed nodejs + npm on my Ubuntu machine using the following commands:
curl -sL https://deb.nodesource.com/setup | bash -
apt-get install -y nodejs
And, in order to use yeoman without sudo I used the following commands:
echo prefix = ~/.node >> ~/.npmrc
export PATH="$PATH:$HOME/.node/bin"
After that, I can't update the NPM. If I run npm update -g npm
the version number doesn't change, but, if I run the update command before the echo prefix
command, the update works and npm is updated.
Upvotes: 3
Views: 1668
Reputation: 231
If you want a well updated nodejs + npm :
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
sudo npm update -g npm
Et voilà!
Upvotes: 0
Reputation: 3515
You have node
+ npm
installed. By default npm
uses /usr/lib/node_modules/
directory to install global modules. Non-priveledged users normally don't have write access to that directory and as such, cannot install npm packages globally.
The command echo prefix = ~/.node >> ~/.npmrc
tells npm
to install global packages to ~/.node/node_modules
instead of usr/lib/node_modules
.
After calling:
echo 'export PATH=$HOME/.node/bin:$PATH' >> ~/.bashrc
all npm
packages which provide binary scripts are added to $PATH (e.g. yo
, browserify
) but also npm
.
npm
package is managed via npm
package manager itself. The following command updates npm
to the latest version:
npm install -g npm
NodeSource provides a binary build of nodejs
+ npm
.
In usage instructions they say to run both commands as admin for Debian systems:
sudo curl -sL https://deb.nodesource.com/setup | bash -
sudo apt-get install -y nodejs nodejs-legacy
The most important line in the setup script is this:
echo 'deb https://deb.nodesource.com/node ${DISTRO} main' > /etc/apt/sources.list.d/nodesource.list
node
+ npm
should be installed on your system globally now. Updates should be managed by apt-get
from now on.
From what I can tell, you have another node
+ npm
installed in your ~/.node
directory. I am not sure why you need it. As far as I know global npm
packages are installed into ~/.npm
directory and they don't interfere with npm
binary installed by apt-get
.
In any way, if you really want to use your custom node installation from ~./node/bin
, you should export $PATH
this way:
export PATH="$HOME/.node/bin:$PATH"
Also you can export $PATH
automatically by adding this command to ~/.bashrc
file:
echo 'export PATH=$HOME/.node/bin:$PATH' >> ~/.bashrc
*NIX looks for binary files (e.g. npm
) in each directory specified in $PATH
. It goes from left to right and executes the first matching binary file it finds. Somewhere in $PATH
variable you have /usr/bin
. If you want to npm
/ node
from ~/.node/bin
to be found first, you should put that directory further to left in the $PATH
environment variable.
Upvotes: 1