I have been trying feverishly to get to the latest version of node and npm on my centos 7 machine.
Unfortunately, I have been plagued with this error for near a week now. And I have finally found a solution that works.
If your npm is currently broken, It is easiest just to install a working version again.
I installed from code. Assuming git is installed, the following commands will accomplish that goal
cd ~
git clone https://github.com/nodejs/node.git nodejs_code
cd nodejs_code
./configure
make
make install
After you have installed a fresh copy of npm and node, which by the way is not the stable version (Instead its bleeding edge right from source).
Installed version of node at time of writing this was 5.0.0-pre which is too new for me, and npm was version 2.14.4 which is too old for me.
To get to the latest version on node, I will install the 'n' package using npm. Using n, I will install the latest version of node.
npm install -g n
n stable
In the case of the root user, (which I use to install global packages) I needed to add the following line to my ~/.bashrc
file, which will allow the root user to access the commands in /usr/local/bin commands. (You may not need this step)
export PATH=/usr/local/bin:$PATH
At this point my version of node is 4.0.0 which is the latest stable version of node.
now to update npm, which was the most annoying thing ever.
Updating directly to the newest version always resulted in "are-we-there-yet" which I could only surmise as "NO, and Quit Asking or I will turn this node around"
Instead I have found that installing through version 3.3.3 first would solve this problem.
npm install -g npm@3.3.3
now version 3.3.3 is installed and works without the "are-we-there-yet" error.
Thank goodness. Keep your arms inside and you seatbelts fastened kids, because we are almost there.....
npm install -g npm
and with that final command, I was able to use the latest version of npm, with the latest stable version of node. Which at the time of writing this is 3.3.5
From here on out, my commands are as follows.
n stable
npm install -g npm
each time I run these from here on out, I am granted undisturbed npm trips without the kids complaining in the back.
Note
As I am moderating a number of servers, none of which come with node by default, I find myself having to perform this task over and over..
Therefore I have taken it upon myself to turn these instructions into a script.
Enjoy:
importnode.sh
#!/bin/bash
cd ~
git clone https://github.com/nodejs/node.git nodejs_code
cd nodejs_code
git reset --hard
git pull origin master
./configure
make
make install
if [[ `cat ~/.bashrc |grep -E "PATH.*/usr/local/bin:.*"` ]];
then
echo "Already Done";
else
echo "export PATH=/usr/local/bin:\$PATH" >> ~/.bashrc;
export PATH=/usr/local/bin:$PATH;
fi;
npm install -g n
n stable
npm install -g npm@3.3.3
npm install -g npm
The only thing left to do after putting this into nodeimport.sh is to make it executable and execute it.
$ chmod +x importnode.sh
$ ./importnode.sh
Wait a while, and all is installed.