Table of Contents
🟢 System Updates and Package Management with APT
✅ What is APT? APT (Advanced Package Tool) is a package management system used on Debian-based Linux distributions (like Ubuntu). It helps you manage software packages—installing, updating, and removing them.
sudo apt update
sudo apt upgrade -y
-y
flag auto-confirms.
sudo apt install mysql-server -y
sudo apt install mongodb -y
-y
for automatic confirmation.
sudo apt remove mysql-server -y
🟢 SYSTEMCTL - System & Service Manager
✅ What is Systemctl? Controls system services on Linux (start, stop, restart, enable, disable, status).
sudo systemctl start mysql
sudo systemctl stop mysql
sudo systemctl enable mysql
sudo systemctl disable mysql
sudo systemctl status mysql
🟢 Handling Files in Linux
✅ Why Manage Files from the Command Line? Managing files from the command line on a VPS is efficient, especially when working remotely. It's faster and often necessary for server management.
# Navigate directories
cd /path/to/directory
# List files
ls -la
# Create a file
touch myfile.txt
# Delete a file
rm myfile.txt
touch
creates an empty file if it doesn't exist.rm
removes a file permanently.
# Read a file
cat myfile.txt
# Write to a file
echo "Hello, World!" > myfile.txt
echo
prints text and can redirect output to files.- Use
>
to overwrite or>>
to append.
sudo nano myfile.txt
nano
opens a simple terminal-based text editor.vi
orvim
are alternatives with more features but a steeper learning curve.
less myfile.txt
less
displays content page by page, allowing navigation.more
does similar but without backward scrolling.
🟢 Node.js and NPM
# Check Node.js version
node -v
# Check NPM version
npm -v
# Install dependencies for project
cd /path/to/project && npm install
# Run Node.js application
npm start
# Install PM2 for process management
npm install -g pm2
# Start application with PM2
pm2 start app.js --name "mern-app"
# List running PM2 applications
pm2 list
# Configure PM2 to start on boot
pm2 startup
Node.js commands for version checking, package management, and running applications with process management using PM2.
🟢 Network Management
# Install UFW
apt install ufw
# Allow specific ports
ufw allow 22 # SSH
ufw allow 80 # HTTP
ufw allow 443 # HTTPS
ufw allow 3000 # Node.js app
# Enable firewall
ufw enable
# Check status
ufw status
Uncomplicated Firewall (UFW) provides an easy way to manage your server's firewall rules to protect your server while allowing legitimate traffic through.
🟢 Monitoring and Troubleshooting
# Check disk space
df -h
# Check memory usage
free -m
# Check system load
top
# or more user-friendly alternative
htop
Essential commands for monitoring system resources including disk space, memory usage, and CPU load to maintain optimal server performance.
Pro Tip: Always check system resources before troubleshooting performance issues. Many problems stem from disk space, memory, or CPU constraints.