General

Upgrade NodeJS in AWS LightSail

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.

temp directory contents

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

New Node version files are copied.

Verify the Installation

Verify the new node and npm versions.

node -v
npm -v

Happy Coding…. 🍺

Computer engineer interested in programming, electronics, application architecture, data visualization, automation and performance optimization.

2 Comments

Leave a Reply