1 min read

SuperUser : Run on startup in Debian-based Linux

This article contains AI generated content verified by a human.

Managing the automatic startup of an application on Debian-based Linux can be done in several ways. For system or server applications, it is recommended to use systemd to create a service. For graphical or personal applications, add to the session startup instead.


Method 1: Create a systemd Service (for system/server applications)

1. Create a service file

Applications requiring a graphical environment should not be launched as a systemd service without special configuration (DISPLAY environment variable, etc). Use this method instead

sudo nano /etc/systemd/system/myapp.service

Example content for a basic service:

[Unit]
Description=My Application
After=network.target

[Service]
Type=simple
ExecStart=/path/to/myapp [arguments]
Restart=on-failure
User=myuser

[Install]
WantedBy=default.target

Replace /path/to/myapp and myuser with your actual values.

2. Enable and start the service

sudo systemctl daemon-reload
sudo systemctl enable --now myapp.service

To check the status:

systemctl status myapp.service

Method 2: Add a Graphical Application to Session Startup

1. Using the graphical tool

  • Menu > Preferences > Startup Applications
  • Click "Add" and fill in the name, command (e.g., copyq), and a comment.

2. Or via command line:

Create a .desktop file in ~/.config/autostart/:

mkdir -p ~/.config/autostart
nano ~/.config/autostart/myapp.desktop

Example content:

[Desktop Entry]
Type=Application
Exec=/path/to/myapp [arguments]
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=MyApp
Comment=Start MyApp on login

Tips and Diagnostics

  • To see all services: systemctl list-units --type=service
  • To disable a service: sudo systemctl disable --now myapp.service
  • To test a .desktop file: gtk-launch MyApp (if Name=MyApp)