How to Install and Remove nodejs from Ubuntu
Please follow the below simple steps to install and remove nodejs from ubuntu.
Install nodejs with a specific version
First, we'll see how to install nodejs with a specific version. Run below commands to install nodejs in your server.
Refresh your local package index using below command
sudo apt-get update
Now we'll install nodejs from NodeSource Repository. We'll use curl to add its
PPA (Personal Package Archive). So, make sure you have installed curl in your server. If you don't have it then you can install it using the below command.
sudo apt-get install curl
Now run the following command with
sudo to enable
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
In the above command, you can change the version according to your requirement. For Ex:
Finally, we are going to install nodejs. Run below command to install
sudo apt-get install nodejs
Above command not only install
nodejs but it also installs
npm and other dependencies as well.
once its install successfully you can check its version using following commands
To Check nodejs version run the below command
node --version //or node -v
And to check
npm version run the below command
npm --version //or npm -v
Uninstall NodeJS from Ubuntu
Run below command to uninstall nodejs from ubuntu.
sudo apt-get remove nodejs
Above commad remove the package but it's configuration files are not remove from your server. If you want to remove both then use below command.
sudo apt-get purge nodejs
It'll remove package and configuration files.
Run the below command to remove unused files from ubuntu and cleanup the disk space. Its optional command, run this command if you want to cleanup the disk space and remove unused files.
sudo apt-get autoremove
Finally, we have successfully uninstall
nodejs from the Ubuntu and cleanup the disk space.
I hope this article helped you to find what you were looking for.
Bookmark it for your future reference. Do comment below if you have any other handy commands which are not included in the list.
P.S. Do share this note with your team.