AWS
How to install NodeJS in Amazon Linux 2
I prefer to run any workloads in a container. However, I always had challenges in using containers in small virtual machines due to CPU & Memory limitations. Recently I spun up an EC2 instance and I had to install NodeJS to run a simple application. Below are the steps I used.
NVM is used to install and manage multiple versions of Node JS.
Step 1: Install NVM
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14926 100 14926 0 0 136k 0 --:--:-- --:--:-- --:--:-- 134k
=> Downloading nvm as script to '/home/ec2-user/.nvm'
=> Appending nvm source string to /home/ec2-user/.bashrc
=> Appending bash_completion source string to /home/ec2-user/.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
Step 2: Verify NVM is installed
Confirm NVM related script is added to the bashrc file.
$ cat /home/ec2-user/.bashrc
# .bashrc
.
.
.
.
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
Confirm nvm is available in a new terminal.
$ nvm ls
N/A
iojs -> N/A (default)
node -> stable (-> N/A) (default)
unstable -> N/A (default)
Step 3: Install Node Versions (14.x)
$ nvm install 14
Downloading and installing node v14.17.3...
Downloading https://nodejs.org/dist/v14.17.3/node-v14.17.3-linux-x64.tar.xz...
############################################################################################################################################################ 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v14.17.3 (npm v6.14.13)
Creating default alias: default -> 14 (-> v14.17.3)
$
$ nvm install 16
Downloading and installing node v16.4.2...
Downloading https://nodejs.org/dist/v16.4.2/node-v16.4.2-linux-x64.tar.xz...
############################################################################################################################################################ 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.4.2 (npm v7.18.1)
$
Check NodeJS versions
$ nvm ls
v14.17.3
-> v16.4.2
default -> 14 (-> v14.17.3)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.4.2) (default)
stable -> 16.4 (-> v16.4.2) (default)
lts/* -> lts/fermium (-> v14.17.3)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.3 (-> N/A)
lts/fermium -> v14.17.3
$
Step 4: Use NodeJS
$ nvm use node 14
Now using node v14.17.3 (npm v6.14.13)
$ node --version
v14.17.3
]$ npm --version
6.14.13
$ nvm use node 16
Now using node v16.4.2 (npm v7.18.1)
$ node --version
v16.4.2
$ npm --version
7.18.1
-
Infrastructure3 years ago
How to test CPU, Memory and File System Performance using Sysbench
-
AWS3 years ago
How to install .Net 6 in Amazon Linux 2
-
Uncategorized3 years ago
How to install Docker in Amazon Linux 2?
-
Infrastructure3 years ago
How to get Linux OS Information using uname command
-
Infrastructure3 years ago
How to reproduce CVE-2021-44228 (Log4J vulnerability), patch it, and validate the fix
-
Uncategorized3 years ago
Everything, Everywhere, All At Once
-
Linux3 years ago
How to install git in Amazon Linux 2
-
Infrastructure3 years ago
Getting started with Terraform CDK and TypeScript