Starting a GUI program when Rasbperry Pi boots

2021/01/25


Go back

To automatically open a GUI program when you boot your Raspberry PI running LXDE, the only way that works as of January 2021 is to add a *.desktop file inside the /home/pi/.config/autostart/ folder.

In my case, I needed to run a .NET 5.0 server app I wrote, and I needed it to run inside a terminal window so the server output was easily visible when connecting via VNC. So I created the file /home/pi/.config/autostart/MyServerName.desktop and added the following lines:

[Desktop Entry]
Type=Application
Name=My .NET 5.0 server autostart
Comment=Start the .NET 5.0 server in a visible LXDE terminal window on boot
NoDisplay=false
Exec=/usr/bin/lxterminal --command="/home/pi/MyServer/Program -some arguments" --working-directory=/home/pi/MyServer
NotShowIn=GNOME;KDE;XFCE;

Rebooted, and the lxterminal window opened as soon as the pi user logged in.

There is a huge number of StackOverflow answers and blog tutorials saying that adding entries to the files /home/pi/.config/lxsession/LXDE-pi/autostart or /etc/xdg/lxsession/LXDE-pi/autostart. Unfortunately, they are all wrong, and there is very little up-to-date information showing what works and what doesn’t.