How to Configure JVM Options and Environment Variables on a Panelless Linux VPS
When running a standalone Java application on an unmanaged, panelless Linux VPS, you have total control over the environment. You configure system arguments manually by passing flags directly through the terminal command line or packaging them inside a persistent systemd system service controller.
Method 1: Running Applications via Command Line
For immediate execution or active development debugging, you can append your custom memory metrics and environment parameters directly to the standalone java -jar initialization string:
- Connect to your server terminal using your SSH terminal program.
- Navigate to the file folder containing your executable jar file and start it up with your custom arguments:
java -Xms512m -Xmx2048m -Dspring.profiles.active=production -jar myapp.jar
Method 2: Creating a Persistent System Service (Systemd)
For permanent production deployments, you should construct a dedicated system manager configuration file. This guarantees that your application starts up automatically during system boots and handles background process scaling perfectly:
- Create a new service configuration document using your terminal editor text manager:
sudo nano /etc/systemd/system/myapp.service - Paste the structural deployment blocks template below, modifying the application path values to match your specific setup:
[Unit] Description=My Production Java Application Backend After=syslog.target network.target [Service] User=vpsuser WorkingDirectory=/var/www/myapp ExecStart=/usr/bin/java -Xms512m -Xmx2048m -Dspring.profiles.active=production -jar myapp.jar SuccessExitStatus=143 Restart=always RestartSec=10 [Install] WantedBy=multi-user.target
- Save the template file and run the following terminal reload commands to start the background management controller:
sudo systemctl daemon-reloadsudo systemctl enable myapp.servicesudo systemctl start myapp.service - You can check your application logs or track execution anomalies anytime by reviewing the system journal output:
sudo journalctl -u myapp.service -n 50 -f