Tuesday, September 24, 2019

JavaScript - Uninstall and re-Install nodejs and npm in Ubuntu 18.04

Since, I wanted to uninstall and re-install the latest stable version of nodejs. 

Step 1: Remove all node versions and nvm

# Remove nvm
sudo rm -rf ~/.nvm
hash -r

# Remove latest node version
sudo npm uninstall -g n

# Remove n
cd ~/src/n && sudo make uninstall && cd .. && sudo rm -r n

# Remove latest nodejs version
sudo apt-get purge -y nodejs npm

# Remove nodejs-legacy version
sudo apt-get purge -y nodejs-legacy npm

sudo apt -y autoremove

# Remove nodejs files
sudo rm -rf /usr/local/lib/node_modules/npm
sudo rm -rf /usr/local/lib/node_modules/n
sudo rm -f /usr/local/bin/node
sudo rm -f /usr/local/bin/npm
sudo rm -f /usr/bin/node
sudo rm -rf /usr/local/n/versions/node


Let us install using NVM. (Node Version Manager)

Step 2: Download the shell script to install nvm:
$ curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh -o install_nvm.sh

Step 3: Install NVM - using shell script:
$ bash install_nvm.sh
You have $NVM_DIR set to "/home/ubuntu/.nvm", but that directory does not exist. Check your profile files and environment.

Since, it couldn't find the .nvm directory as it got removed during the uninstallation process. Hence, we will manually re-create it.

Step 4: Make directory .nvm: 
$ mkdir .nvm

Hence, Rerunning command in Step 3: 
$ bash install_nvm.sh
=> Downloading nvm from git to '/home/ubuntu/.nvm'
=> Cloning into '/home/ubuntu/.nvm'...
remote: Enumerating objects: 267, done.
remote: Counting objects: 100% (267/267), done.
remote: Compressing objects: 100% (242/242), done.
remote: Total 267 (delta 31), reused 80 (delta 15), pack-reused 0
Receiving objects: 100% (267/267), 119.47 KiB | 344.00 KiB/s, done.
Resolving deltas: 100% (31/31), done.
=> Compressing and cleaning up git repository

=> nvm source string already in /home/ubuntu/.bashrc
=> bash_completion source string already in /home/ubuntu/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
$

Step5 : List down the LTS releases:

$ nvm ls-remote | grep "Latest LTS"
         v4.9.1   (Latest LTS: Argon)
        v6.17.1   (Latest LTS: Boron)
        v8.16.1   (Latest LTS: Carbon)
->     v10.16.3   (Latest LTS: Dubnium)


Step 6: Now let us install Node.js:

$ nvm install 10.16.3
Downloading and installing node v10.16.3...
Downloading https://nodejs.org/dist/v10.16.3/node-v10.16.3-linux-x64.tar.xz...
####################################################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.16.3 (npm v6.9.0)
Creating default alias: default -> 10.16.3 (-> v10.16.3)

Step 7: Check the Node and NPM Versions:

$ node --version
v10.16.3

$ npm --version
6.9.0



References:


2 comments:

  1. nice informative post. Thanks you for sharing.
    We are an experienced team in one of the Best software company and product specialist for software development and implementation.
    Wordpress Development

    NodeJS Development

    ReplyDelete
  2. 1xbet korean 2021 - legalbet.co.kr
    The choegocasino official and safe online sports betting 바카라사이트 partner of the best bookmakers in the industry, 1xbet korean 1xbet.co.uk, founded in 2018.

    ReplyDelete