Hướng dẫn cài đặt Node.js với Node Version Manager (NVM) trên Almalinux 9
1. Node.js là gì?
Node.js là một nền tảng mã nguồn mở chạy JavaScript phía máy chủ (server-side) được xây dựng dựa trên công cụ JavaScript V8. Node.js cho phép bạn chạy JavaScript bên ngoài trình duyệt, điều này giúp cho Node.js hoạt động rất hiệu quả trong việc phát triển các ựng dụng mạng nhanh như API Backend, các ứng dụng thời gian thực chat, streaming ...

2. Cài đặt Node.js với NVM (Node Version Manager)
Có nhiều cách để cài đặt Node.js, tuy nhiên trong bài viết này iNET sẽ hướng dẫn các bạn cài đặt Node.js với NVM để dễ dàng cài đặt và quản lý nhiều phiên bản Node.js trên cùng một hệ thống.
- Bước 1: Cài đặt NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bashKết quả:
[user@localhost ~]$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16631 100 16631 0 0 37541 0 --:--:-- --:--:-- --:--:-- 37457
=> Downloading nvm as script to '/home/user/.nvm'
=> Appending nvm source string to /home/user/.bashrc
=> Appending bash_completion source string to /home/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_completionKiểm tra kết quả và phiên bản NVM vừa cài đặtL
[user@localhost ~]$ source ~/.bashrc
[user@localhost ~]$ nvm --version
0.40.1- Bước 2: Cài đặt Node.js với NVM
Liệt kê các phiên bản Node.js có sẵn và cài đặt phiên bản Node.js mong muốn (Ví dụ: v21.6.0)
[user@localhost ~]$ nvm ls-remote
v0.1.14
v0.1.15
v0.1.16
v0.1.17
[user@localhost ~]$ nvm install v21.6.0
Downloading and installing node v21.6.0...
Local cache found: ${NVM_DIR}/.cache/bin/node-v21.6.0-linux-x64/node-v21.6.0-linux-x64.tar.xz
Checksums match! Using existing downloaded archive ${NVM_DIR}/.cache/bin/node-v21.6.0-linux-x64/node-v21.6.0-linux-x64.tar.xz
Now using node v21.6.0 (npm v10.2.4)
Creating default alias: default -> v21.6.0
Chọn phiên bản Node.js mặc định:
[user@localhost ~]$ nvm alias default v21.6.0Kiểm tra lại phiên bản Node.js hiện tại:
[user@localhost ~]$ node --version
v21.6.0
3. Lời kết
Trên đây là hướng dẫn chi tiết về "Cài đặt Nodejs với Node Vesion Manager (NVM) trên Almalinux 9". Chúc các bạn thực hiện thành công.