Skip to main content

Detailed Guide: Run Gunbot on a Linux VPS with PM2

ยท 6 min read

If you're engaged in cryptocurrency trading, you know that every bit of advantage counts. You have the knowledge, the strategy, and possibly the best automation tool at your disposal โ€“ Gunbot. But did you know you can push its efficiency even further by running it on a Virtual Private Server (VPS) with PM2? It's an option not only for power users but anyone seeking an edge in their trading game.

Symbol image of setting up a gunbot server

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

Running Gunbot on a server has distinct advantages. It provides independence from your computer, reducing the risk of disruptions due to power outages or system crashes. Furthermore, it allows for 24/7 operation, ensuring you never miss a trade even when you're offline. The great news is, you don't have to break the bank for it! Affordable servers with at least 4GB RAM, like those from Hetzner Cloud or Contabo, are perfectly capable.

Now let's dive into this step-by-step guide that will walk you through this process. We'll start by understanding the perks of using PM2, then move onto setting up your VPS, installing Gunbot and PM2, managing your Ubuntu firewall, working with logs, and more.

Benefits of PM2โ€‹

PM2 is an advanced production-level process manager for Node.js applications. ๐Ÿš€ It simplifies the process of running your application in the background as a daemon, allowing you to manage application logging, monitoring, and clustering.

Using PM2 brings several advantages:

  • Process Management: PM2 allows you to easily manage your application's status, restart, shutdown, and overall system health.
  • Logging & Monitoring: PM2 automatically maintains logs and provides an easy way to watch them, flush them, and start doing logrotate.
  • Startup Scripts: PM2 comes with a built-in script to generate startup scripts and configure them in order to restart your applications on a machine reboot.

Setting Up Your VPSโ€‹

Before we start, ensure you've followed the instructions provided by your VPS provider to set up your server. Ubuntu is a commonly used operating system due to its user-friendly nature and extensive community support.

You can connect to your server using SSH (Secure Shell), which is a protocol providing secure access to remote servers. Depending on your personal computer's OS, different tools offer integrated SSH connection and file management features. For Windows users, MobaXterm is a good choice. Linux users can go for Remmina, and Mac users might find WindTerm useful.

Installing Gunbot and PM2 on Your VPSโ€‹

Before proceeding, you need to download the latest Gunbot release from the stable channel. Upload the file to your server to your preferred folder. This can be done using the built-in file transfer function in any of the previously mentioned SSH clients. Once uploaded, unpack it using the following commands (first navigate to the folder where you've uploaded the file):


To install PM2, you should first install Node.js and npm (Node Package Manager). Use these commands in your terminal:

sudo apt update
sudo apt install nodejs npm -y

Then install PM2 using npm:

npm install pm2@latest -g

Now, you can start your Gunbot as a named process in PM2. This will allow it to be spawned again when the system restarts:

pm2 start gunthy-linux --name myGunbotProcess

In this example, myGunbotProcess is the name given to the process. You can choose any name you prefer.

Configuring the Firewallโ€‹

It's vital to ensure that the port set for the Gunbot interface is accessible from the server. By default, Gunbot uses port 5000. You can allow connections to this port using the following command:

sudo ufw allow 5000

Do remember, your VPS provider might also have an added firewall layer in its interface that requires port settings. Check with your provider for specific instructions.

Working with Logs and PM2 Logrotateโ€‹

PM2 makes handling logs quite simple:

# Display all processes logs 
pm2 logs
# Display only myGunbotProcess logs
pm2 logs myGunbotProcess
# Empty all logs
pm2 flush

To manage log rotation, install pm2-logrotate:

pm2 install pm2-logrotate

This module automatically rotates your logs and prevents them from consuming too much disk space.

Restarting Named Processes after System Restartโ€‹

With PM2, restarting all named processes after a system restart is straightforward:

pm2 startup
pm2 save

The first command generates a startup script for the processes that are currently running, and the second one saves it.

Updating Gunbotโ€‹

Info: Usually it is possible to upgrade Gunbot just by replacing the executable gunthy-linux file in the folder of a working bot. Do read the upgrade instructions when a new stable comes out.

When updating Gunbot, follow these steps:

  1. Stop the current process with PM2:
pm2 stop your-process-name
  1. Upload the new gunthy-linux file to the correct folder on the server.
  2. Restart the process:
pm2 restart your-process-name

Bonus: Run Multiple Gunbot Instances on One Serverโ€‹

With PM2, running multiple instances of Gunbot on a single server becomes effortless. Each instance should have a unique process name.

First copy a working Gunbot folder to a new folder, navigate to the folder, then change 3 settings in the config.js file to be unique for this bot instance. Open the config file with the Nano text editor like this:

nano config.js

Now repeat the start command for each instance:

pm2 start gunthy-linux --name "another-process-name"

To save the processes you again run:

pm2 startup
pm2 save

In conclusion, running Gunbot on a VPS offers undeniable advantages like uptime assurance, independent operations, and remote accessibility, especially with powerful tools like PM2. Remember, it doesn't have to break your bank! Affordable options like Hetzner Cloud or Contabo are perfect examples of that.