Keeping your Next.js app updated on your VPS is simple when you follow the right steps. Whether youβre pushing updates or deploying a fresh version, this quick guide will walk you through the process β from pulling the latest code to restarting your app with PM2.
Use SSH to access your server:
ssh root@your-server-ip
Make sure you have access permissions and the necessary SSH key or credentials.
Move to the directory where your Next.js app lives (or where you want to deploy it):
cd /var/www/html/directory
Update the path if your project is located elsewhere.
Make sure youβre in the correct Git branch (e.g. main
), then pull the latest updates:
git pull origin main
This will sync your server with the latest code from your remote repository.
Next.js apps must be built before running in production:
npm install # if any dependencies changed
npm run build # build the latest version of the app
This compiles the app and prepares it for production.
If your app is already managed by PM2, Read This If You didn’t Added Your Service on PM2:
pm2 restart your-app-name
Thatβs it! Your Next.js app is now updated and running the latest version.
Enjoy your app β faster, smarter, and up-to-date π