Well recently, It happens that I need to update my nodejs package on my ubuntu server (18.04.2). I type
node -v and see that it is v8.x something and the LTS version now is 10.16.3, so I set out to upgrade it. After following some simple guides online, I simply can’t get it to work. Even after I installed the latest nodejs, the version checking still gives me the old version with both node and npm. WTH!
Without the time to dive in and find out what is the culprit, I completely removed previous node and npm stuff on my ubuntu using good old
sudo rm -rf node-shit following this guide https://amcositsupport.blogspot.com/2016/07/to-completely-uninstall-node-js-from.html
Then I see many guides say that you have to first execute
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
before running this
sudo apt-get install -y nodejs
So, firstly after running the curl command above, there’s a line of text near the end saying ## Run `sudo apt-get install -y nodejs` to install Node.js 10.x and npm. So then I run
sudo apt-get install -y nodejs, and
nodejs -v gives me
10.16.3. Great! Next I do
npm -v, well…the console gives out
-bash: /usr/local/bin/npm: No such file or directory
Shit! WTH! Even more bad news, I can’t even get the nvm approach to install my node and npm as well…I’m starting to doubt that it is my server’s peculiar case but not that those guides have failed others.
After two hours of trying, finally I saw the holy light in the dark! https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04 is my ultimate lifesaver.
I have to follow its “Installing Using a PPA” approach in order to make things work. God bless the guy who wrote this guide! I guess the magic in this working approach is in its nodesource_setup.sh file. I really hope that this can save someone who is in the same weird shit situation that I once was.