Quick answer
How do you run a Telegram bot on a VPS?
To run a Telegram bot on a VPS, create a bot user, put the code in /opt/bot with a Python venv, store the token in a root-only file, then add a systemd service with Restart=always. The bot then restarts 5 seconds after any crash and starts at boot. A 1 GB JadeKVM Bead plan is enough.
In brief
- Long polling needs no open port; a webhook needs HTTPS on 443, 80, 88 or 8443.
- Token in an EnvironmentFile with mode 600, never in the code repository.
- Restart=always keeps the bot alive after crashes and reboots.
- Logs in the journal:
journalctl -u tgbot -ffollows them.
How to run a Telegram bot on a VPS in 6 steps?
The example uses Python; the systemd part is the same for Node.js or Go bots.
Get a token
Create the bot with BotFather in Telegram and copy the token it gives.
Create a bot user
Run
sudo adduser --system --group --home /opt/bot tgbot.Install the code
Copy bot.py to /opt/bot, create a venv and install python-telegram-bot.
Store the token
Write BOT_TOKEN to /etc/tgbot.env and set mode 600.
Add the service
Write /etc/systemd/system/tgbot.service with Restart=always.
Start and watch
Run
sudo systemctl enable --now tgbotand follow the journal.
Which update method should the bot use?
| Method | Open port | HTTPS needed | Fits |
|---|---|---|---|
| Long polling (getUpdates) | None | No | Most bots, simplest setup |
| Webhook (setWebhook) | 443, 80, 88 or 8443 | Yes | High traffic, many updates per second |
| Both at once | Not possible | Not applicable | The API refuses getUpdates while a webhook is set |
How do you install the bot code in a virtual environment?
Create a venv in /opt/bot, install the library there, and own the folder by the bot user. A venv keeps the bot's packages apart from the system Python. Debian 13 and Ubuntu 24.04 block pip installs into the system Python, so the venv is the clean path.
sudo apt install -y python3-venv
sudo adduser --system --group --home /opt/bot tgbot
sudo python3 -m venv /opt/bot/venv
sudo /opt/bot/venv/bin/pip install python-telegram-bot
sudo cp bot.py /opt/bot/
sudo chown -R tgbot:tgbot /opt/bot
echo 'BOT_TOKEN=123456:replace-with-your-token' | sudo tee /etc/tgbot.env > /dev/null
sudo chmod 600 /etc/tgbot.envHow do you make the Telegram bot restart on its own?
A systemd unit with Restart=always and RestartSec=5 restarts the bot after any exit. systemd reads the token file as root before it drops to the tgbot user, so the bot sees BOT_TOKEN without reading the file itself. Read it in the code with os.environ['BOT_TOKEN'].
After any change to the unit, run sudo systemctl daemon-reload. Then restart the service.
[Unit]
Description=Telegram bot
After=network-online.target
Wants=network-online.target
[Service]
User=tgbot
WorkingDirectory=/opt/bot
EnvironmentFile=/etc/tgbot.env
ExecStart=/opt/bot/venv/bin/python /opt/bot/bot.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetWhich is the best VPS location for a Telegram bot in 2026?
Choose the city nearest your users or the APIs the bot calls; for most bots the gap is small. JadeKVM read WonderNetwork's public pings on 16 November 2026: Singapore sits 15 ms from Jakarta and 55 ms from Mumbai, Hong Kong 14 ms from Taipei. Latency figures on JadeKVM pages are public averages measured by WonderNetwork between its own servers on 16 November 2026; they show how far apart the cities sit on the network, not a promise about any one JadeKVM server.
If the bot sends scheduled messages, set the right zone first with how to set the timezone on an Asia VPS. A webhook bot also needs a free SSL certificate.
What can the bot not do on a JadeKVM server?
It cannot send mail on port 25, and it must follow the acceptable use rules. Outbound port 25 is closed on every server; send mail through a mail provider on port 465 or 587. Spam and bulk messaging are forbidden; read the acceptable use policy before you launch a broadcast bot. Bead offers 1 shared vCPU, 1 GB RAM, 20 GB NVMe, 1 TB a month, which fits most bots.
Questions about running a Telegram bot on a VPS
Does a Telegram bot need a public IP?
Not for long polling: the bot connects out to Telegram. A webhook needs a public HTTPS address, which every JadeKVM server has.
How much RAM does a Telegram bot need?
A Python bot usually uses under 100 MB. A 1 GB plan leaves room for a small database too.
Is systemd better than screen or tmux for a bot?
Yes. screen does not restart a crashed bot or start it at boot; systemd does both.
Which webhook ports does Telegram allow?
443, 80, 88 and 8443, as the Bot API documentation lists.
How do I update the bot code?
Copy the new files, then run sudo systemctl restart tgbot. The journal shows any start-up error.
Verdict
- A venv, a root-only token file and a systemd unit with Restart=always keep a bot online 24/7.
- Long polling is the simplest choice; switch to a webhook only when traffic demands it.
Sources (6)
- Telegram Bot API — Telegram (read 2026-11-16)
- Bots: An introduction for developers — Telegram (read 2026-11-16)
- python-telegram-bot documentation — python-telegram-bot (read 2026-11-16)
- venv, creation of virtual environments — Python Software Foundation (read 2026-11-16)
- systemd.service(5) manual page — freedesktop.org / systemd (read 2026-11-16)
- WonderNetwork: pings from Singapore wondernetwork.com/pings/Singapore — WonderNetwork (read 2026-11-16)
Give your bot a home in Asia
Bead fits most bots for $3.75 a month on 12 months.
- Built by a person, 1 hour at most after confirmation
- Lost days credited back if a server cannot be delivered
- Pay in BTC, XMR, USDT, USDC, ETH, SOL or LTC
- DomaineGoat LLC · Panama