If you are building a kiosk, a digital signage display, or just want your favorite tools ready when you boot up your Raspberry Pi, you need a reliable way to handle autostart. While there are many ways to do this, using the autostart directory is the cleanest and most reliable method for GUI applications.
Why not use systemd?
Many tutorials suggest using systemd or rc.local. While these are great for background services, they often trigger too early—before the desktop environment (GUI) is actually loaded. By using the method below, we ensure the script only runs once the desktop is ready.
Step-by-Step Guide
1. Create the Autostart Directory
First, we need to ensure that the local autostart directory exists. Open your terminal and run:
mkdir -p /home/pi/.config/autostart
2. Create the Desktop Entry
Next, create a new configuration file. You can name it after your application:
nano /home/pi/.config/autostart/my-application.desktop
3. Add the Configuration
Copy and paste the following content into the editor. Replace the path in Exec with the actual location of your script or application:
[Desktop Entry]
Type=Application
Name=My Startup Application
Exec=/home/pi/path/to/your/script.sh
X-GNOME-Autostart-enabled=true
Pro Tip: Ensure your script is executable by running chmod +x /home/pi/path/to/your/script.sh before rebooting.
Summary
This method is the "Goldilocks" solution for Raspberry Pi users: it's not a complex "systemd hack," and it works perfectly within the standard desktop environment. Once you reboot, your application will launch automatically as soon as the desktop appears.
