The following is a structured, production-oriented setup guide for a fresh Ubuntu 24.04 VPS, including Node.js, MongoDB, and Redis installation.
Synchronize package lists and upgrade installed packages:
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -yReboot if the kernel was upgraded:
sudo rebootUbuntu uses UFW (Uncomplicated Firewall).
Enable UFW and allow SSH:
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw statusIf you later deploy a web server:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcpAvoid operating as root.
sudo adduser yourusername
sudo usermod -aG sudo yourusernameSwitch to the new user:
su - yourusernameEdit SSH configuration:
sudo nano /etc/ssh/sshd_configModify:
PermitRootLogin no
PasswordAuthentication no
(Optional) Change default SSH port:
Port 2222
Restart SSH:
sudo systemctl restart sshIf you changed the port:
sudo ufw allow 2222/tcpOn your local machine:
ssh-keygen
ssh-copy-id yourusername@your_server_ipTest login before closing your current session.
sudo apt install -y fail2ban unattended-upgrades htop curl git build-essentialEnable automatic security updates:
sudo dpkg-reconfigure --priority=low unattended-upgradesNow install Node.js, MongoDB, and Redis properly using official repositories.
Ubuntu repositories are often outdated. Use NodeSource.
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejsVerify installation:
node -v
npm -vOptional: Install PM2 (process manager for production apps)
sudo npm install -g pm2
pm2 startupUbuntu 24.04 requires MongoDB 7.x+.
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
--dearmorecho "deb [ arch=amd64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] \
https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/7.0 multiverse" | \
sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.listsudo apt update
sudo apt install -y mongodb-orgsudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongodVerify:
mongoshEdit MongoDB config:
sudo nano /etc/mongod.confEnsure binding only to localhost:
bindIp: 127.0.0.1Restart:
sudo systemctl restart mongodIf exposing publicly, configure authentication first (never expose without auth).
Ubuntu 24.04 includes Redis 7+ in default repo.
sudo apt install -y redis-serverEnable and start:
sudo systemctl enable redis-server
sudo systemctl start redis-serverTest:
redis-cli pingExpected output:
PONG
Edit configuration:
sudo nano /etc/redis/redis.confEnsure:
bind 127.0.0.1
protected-mode yes
Restart Redis:
sudo systemctl restart redis-serversudo apt install -y nginx
sudo systemctl enable nginxsudo apt install -y certbot python3-certbot-nginxsudo apt install -y net-tools