Skip to main content

Detailed Guide: Run Gunbot on a Linux VPS with PM2

@boekenbox
@boekenbox
Detailed Guide: Run Gunbot on a Linux VPS with PM2
Detailed Guide: Run Gunbot on a Linux VPS with PM2

This guide explains how to set up Gunbot, a cryptocurrency trading automation tool, on a Linux Virtual Private Server (VPS) using PM2. Running Gunbot on a VPS keeps your trading bot online 24/7, independent of your personal computer, minimizing the risk of downtime.

This guide looks at how to run Gunbot on a budget-friendly VPS using PM2.

Benefits of PM2​

PM2 is a process manager for Node.js applications that simplifies managing Gunbot:

  • Process Management: Easily start, stop, and restart Gunbot.
  • Logging and Monitoring: Automatically handles logs and simplifies log management.
  • Startup Scripts: Restarts Gunbot automatically after a server reboot.

Setting Up Your VPS​

Before proceeding, set up your Linux VPS following your provider's guidelines. Ubuntu is recommended for its simplicity and broad support. For a broader walkthrough beyond this PM2-focused flow, see the Gunbot Unlimited quickstart.

Connect to your server via SSH using a tool compatible with your operating system:

Installing Gunbot and PM2​

Download the latest stable Gunbot release (gunthy_linux.zip) and upload it to your VPS using your SSH client. Then, unzip it:

unzip gunthy_linux.zip

Next, install Node.js, npm, and PM2:

sudo apt update
sudo apt install nodejs npm -y
npm install pm2@latest -g

Start Gunbot using PM2 (replace myGunbotProcess with your chosen name):

pm2 start gunthy-linux --name myGunbotProcess

Configuring Firewall​

To access Gunbot from your browser, allow its default port (3001) through Ubuntu's firewall (UFW):

sudo ufw allow 3001/tcp

If your VPS provider has a separate firewall, allow the same port there. You can then open http://YOUR_VPS_IP:3001 in your browser. Opening the port makes the Gunbot login page reachable from the internet, so use a strong password.

Optional: restrict access further​

If you have a fixed public IP address, you can allow only that address instead of opening the port to everyone. Remove the broad rule first:

sudo ufw delete allow 3001/tcp
sudo ufw allow from YOUR_PUBLIC_IP to any port 3001 proto tcp

Alternatively, you can keep port 3001 closed and connect through an SSH tunnel. If you already added the broad UFW rule above, remove it with sudo ufw delete allow 3001/tcp first. This is optional and requires SSH access to your VPS:

ssh -L 3001:127.0.0.1:3001 your-user@your-vps

With the tunnel open, visit http://127.0.0.1:3001 on your own computer. Replace 3001 if you configured Gunbot to use a different port.

Managing Logs with PM2​

Use PM2 commands to manage logs easily:

# View all process logs
pm2 logs

# View logs for a specific process
pm2 logs myGunbotProcess

# Clear all logs
pm2 flush

Set up automatic log rotation to prevent logs from growing too large:

pm2 install pm2-logrotate

Automatically Restarting Gunbot on System Reboot​

Configure PM2 to automatically restart Gunbot after reboot:

pm2 startup
pm2 save

Updating Gunbot​

To update Gunbot, follow these steps:

  1. Stop Gunbot:
pm2 stop your-process-name
  1. Upload and replace the existing gunthy-linux file.
  2. Restart Gunbot:
pm2 restart your-process-name

Always review Gunbot’s official upgrade instructions when updates are available.

Running Multiple Gunbot Instances​

To run multiple Gunbot instances on a single server:

  1. Duplicate your Gunbot folder for each instance.
  2. Modify config.js in each folder to have unique settings (instructions for multiple instances):
nano config.js
  1. Start each Gunbot instance with a unique name:
pm2 start gunthy-linux --name "another-process-name"

Save your configuration for automatic restarts:

pm2 startup
pm2 save

Using Gunbot with PM2 on a Linux VPS provides a reliable, always-on environment suitable for automated cryptocurrency trading. Affordable VPS options like Hetzner Cloud or Contabo can be enough for many Gunbot setups.