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:
1 | 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):
1 | 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:
1 | 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:
1 2 | 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:
1 | 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