We will discuss how to upgrade NodeJS version in an Amazon LightSail instance.
SSH into your AWS LightSail instance.
Get the current NodeJS version
First get the NodeJS version and where its installed.
node -v
The above command will display the currently installed node version.
Now get the where Node JS is installed
which node
This will display the node location. We need this later.
Update Package Lists
Before installing a new version of Node.js, it’s a good practice to update your package lists.
sudo apt-get update
Download and Install Node.js
We will install the node version 20.0.1. Change this to version of your choice. The below example commands will be using version 20.0.1
Create a folder to download the files. We will create a folder named temp
mkdir temp
cd temp
Now we have created the directory and opened it
You can download the Node.js 20.10.0 binary from the official website and install it. Execute below commands one by one.
# Replace “20.10.0” with the actual version number
wget https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz
tar -xf node-v20.10.0-linux-x64.tar.xz
Now your directory should look like this.
Now we will rename the existing node folder to node-old.
Navigate to the current node parent installation directory which we got from the above command which node
. In our case the parent directory is /opt/bitnami
sudo mv node node-old
sudo mkdir node
Now navigate back to our temp
directory and copy the new node files to the new node
directory we created above.
sudo cp -r node-v20.10.0-linux-x64/* /opt/bitnami/node
Verify the Installation
Verify the new node and npm versions.
node -v
npm -v
Happy Coding…. 🍺
2 Comments
Hugh
Thanks for writing this up it worked for me. Only thing is did you mean sudo mv node node-old instead of sudo rm node node-old?
kiranvj
Yes Hugh, you are right. Fixed the command. Thank you 🙂