You can configure a GUI program to start automatically on boot in Raspberry Pi OS using one of several methods.
Method 1: LXDE Autostart
If you are using the desktop environment LXDE (Lightweight X11 Desktop Environment), which is used by Raspberry Pi OS, you can put a .desktop file in the autostart directory. Here’s how to do that:
-
Open Terminal.
-
Type this command and hit enter:
nano ~/.config/lxsession/LXDE-pi/autostart
-
Add the command to execute your program at the end of this file. It might look like this:
@/usr/bin/realdash
-
Save the file and exit nano (Ctrl+X, then Y, then Enter).
-
Reboot to see the changes.
Method 2: systemd
If the first method doesn’t work, or you want a more powerful and flexible solution, you can use systemd, a system and service manager for Linux. Here’s how:
-
Create a new systemd service file:
sudo nano /etc/systemd/system/realdash.service
-
Add the following to this file:
[Unit] Description=RealDash [Service] ExecStart=/usr/bin/realdash Restart=always User=pi Environment=DISPLAY=:0 Environment=XAUTHORITY=/home/pi/.Xauthority [Install] WantedBy=multi-user.target
-
Save the file and exit nano (Ctrl+X, then Y, then Enter).
-
Enable the service so that it starts on boot:
sudo systemctl enable realdash.service
-
Start the service immediately:
sudo systemctl start realdash.service
-
Check the status of the service:
sudo systemctl status realdash.service
Remember that GUI applications usually require a display to connect to, which is why we’ve set the DISPLAY environment variable in the systemd service.
These instructions should help you automatically start a GUI application when your Raspberry Pi boots.