How can I add npm (node.js package manager) to the PATH?
Asked Answered
G

3

9

I installed node.js like this:

cd /usr/local/bin/
git clone --depth 1 http://github.com/joyent/node.git
cd node
git checkout origin/v0.4 # optional.  Note that master is unstable.
export JOBS=2 # optional, sets number of parallel commands.
mkdir ~/local
./configure --prefix=$HOME/local/node
make
make install
echo 'export PATH=$HOME/local/node/bin:$PATH' >> ~/.profile
source ~/.profile

Then I executed this curl http://npmjs.org/install.sh | sh to install npm. After I logged out and logged back in, npm command wasn't recognized:

[/usr/local/bin/node]# npm install now
-bash: npm: command not found

What should I add to the PATH to have npm working?

Gasp answered 22/6, 2011 at 11:26 Comment(0)
U
17

Try this:

git clone https://github.com/npm/cli
cd npm/cli
sudo make install

That advice comes from of https://github.com/isaacs/npm#readme.

It is not as cute as curl|sh, but works.

Utilize answered 22/6, 2011 at 13:33 Comment(6)
apart from rm -rf / what does xmas do?Blame
ASCII art, obviously! (Spoiler alert, there are xterm colors involved)Utilize
I'm getting this: fatal: unable to connect a socket (Connection timed out) Clone of 'git://github.com/isaacs/abbrev-js.git' into submodule path 'node_modules/abbrev' failed make: *** [submodules] Error 1Gasp
That's odd. Is your ethernet cable unplugged?Utilize
No, I'm doing these steps on a shared hosting server with +100 days of uptime!Gasp
The github.com/npm/npm.git repository is no longer used and has been archived. github.com/npm/cli should be used.Anthropography
S
2

Great news : npm now comes with nodejs !

Seagirt answered 28/1, 2013 at 8:18 Comment(2)
True, and yet still with node and npm both in /usr/local/bin I can run node but not npm from the terminal :(Impartial
And still not installed from yum install nodejsNombril
P
0

I am a beginner~, but I want be helpful.

I use centos7, and do you know yum (a tool could download and setup programs like mirosoft Windows)

First, I search keyword "node.js" at wiki.centos, I find this. https://wiki.centos.org/SpecialInterestGroup/SCLo/CollectionsList?highlight=%28node.js%29. There are two versions of nodejs could be used at the moment, I chose the higher one. the URL is https://www.softwarecollections.org/en/scls/rhscl/rh-nodejs4/ and the command lines are below:

# Install a package with repository for your system:
# On CentOS, install package centos-release-scl available in CentOS repository:
$ sudo yum install centos-release-scl-rh

# On RHEL, enable RHSCL repository for you system:
$ sudo yum-config-manager --enable rhel-server-rhscl-7-rpms

# 2. Install the collection:
$ sudo yum install rh-nodejs4

# 3. Start using software collections:
$ scl enable rh-nodejs4 bash
Peon answered 22/6, 2017 at 3:6 Comment(2)
I think it a very easy way to install nodejs than manual, wish you happy!Peon
Welcome to Stack Overflow! I would like to note that this particular post is 6 years old at this point and already has another answer accepted, so it's unlikely your answer may be seen by a large number of people.Triglyceride

© 2022 - 2024 — McMap. All rights reserved.