Upgrade nodejs on Ubuntu (Amazon EC2)

Shan Dou
1 min readJun 12, 2019

--

To prepare for a partial deployment of a next.js app, I needed to upgrade both nodejs and npm on our Amazon EC2 server. Directly running npm install -g npm did not work likely due to the ancientness of our nodejs.

After some search around, one SO answer works the best:

The sequence of commands I ended up running for the upgrade is:

# 1. Clean up to avoid conflicts
sudo apt purge nodejs npm
# 2. Install nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
# 3. Install new node via nvm
nvm install node
# 4. The above command will write the necessary path information into ~/.bashrc. To be able to use updated node, we must reload
source ~/.bashrc

--

--

Shan Dou
Shan Dou

Responses (1)