Tue Feb 21 2017
Paul Shan
Many a times you face issues with the version of your installed node js. Some packages may ask for latest versions to work smoothly and some others may say they can not work properly with the latest versions. So sometimes the versions of node js really become a headache and you face the requirement to upgrade or downgrade them.
There are couple of ways to do that and I’ve found one of the most popular ways people described is by using the npm package n
.
But I found it not up to the mark due to the following reasons.
sudo
.nvm
. Right now nvm
has 3 times the stars than n
in github.I think you already guessed what I want to say. Yes, I think nvm
is a better and secure way to update, manage or remove your node js versions. I personally am doing upgrade and downgrade all the times now a days because I work both with ember-cli and angular-cli. Ember-cli wants the node to be below v6.9 and angular-cli wants it above 6.9. So you can guess my situation.
First of all you need to have nvm
(node version manager) installed in your computer. You can run the following curl
command to install that.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
This should be sufficient to install nvm
properly without errors. However if you want to check details or other ways about installation, you can check the document in github.
Now that your nvm is installed and ready to be used; install the required version of node.js using nvm in your computer. The command below will so it for you.
nvm install 7.0.0
You can install multiple versions of node js too.
Now that your desired version of node js is installed; you can switch to that using the command below.
nvm use 7.0.0
The command above will make the current used version of node js in your computer as 7.0.0. To verify it, you can run the version command of node.
node -v
#7.0.0
If any any point you want to see which versions are installed, you can run the following nvm command to list all of them.
nvm ls
Even though multiple installed versions will not bother you; as at a time you will be using only one. But if you feel you have some unnecessary versions you can always remove them using the following command.
nvm uninstall 6.0.0
Many a time you need to install the latest available node.js in your machine. However going to the official node.js website, finding out the latest version and installing and running that using the previously mentioned steps are a little tedious task. That’s why I’ve came up with the following bash function.
update_nodejs () {
NODE_CURRENT=$(nvm_ls_current)
NODE_LATEST=$(nvm_remote_versions | grep '^v' | tail -1)
echo "Updating node.js from ${NODE_CURRENT} to ${NODE_LATEST}..."
nvm install ${NODE_LATEST}
nvm use ${NODE_LATEST}
}
All you need to do is to open up your .bash_profile
and insert this code snippet over there. Restart your terminal & you will be able to use the command update_nodejs
, which will update the node.js in your machine to the latest version.
There is a problem with nvm when using global packages. If you install a package globally and then switch the node js version to some other; you wont be able to access the the global package there. To resolve this, check how to forward global packages in nvm.
SHARE THIS ARTICLE
Thu Mar 10 2016
OAuth authentications are pretty popular now a days and another thing which is popular is JavaScript. This article shows how to plugin google’s oAuth api for authentication in your own node application.Sat Mar 01 2014
This is a continuation of my CSS3 loader snippet collection series. I've provided spinning css3 animation loader in the part 1 of this series and here in part 2, I'm providing various square type loading