ホーム > AWS > How to Install Node.js on EC2
AWS

How to Install Node.js on EC2

Thank you for your continued support.
This article contains advertisements that help fund our operations.

This article summarizes how to install Node.js on EC2.

Error Message

npm install

bash: npm: command not found

This solution also addresses the issue when the command is not found while attempting something like npm install.

How to Install Node.js on Amazon Linux 2023

curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo dnf install -y nodejs
node -v
npm -v

With these two commands, you can install Node.js, and by running the version check commands, you can verify that the installation was successful.

How to Install Node.js on Amazon Linux 2

If necessary, run the following command:

sudo yum update

With the following two commands, you can install Node.js, and by running the version check commands, you can verify that the installation was successful.

curl -sL https://rpm.nodesource.com/setup_8.x | sudo bash -
sudo yum install -y nodejs
node -v
npm -v

You have now installed the latest version of Node.js.

Differences Between Amazon Linux 2023 and Amazon Linux 2

The package manager differs, with Amazon Linux 2023 using dnf and Amazon Linux 2 using yum, leading to slight differences in commands.

The same command changes may apply to other packages, depending on the Linux version, so take care to note these differences.

I hope this is helpful.

Please Provide Feedback
We would appreciate your feedback on this article. Feel free to leave a comment on any relevant YouTube video or reach out through the contact form. Thank you!