How to Auto Start a Program on Raspberry Pi? (4 Ways)
You may want to launch a script or program on boot, but you don’t see an option for it on Raspberry Pi OS. It’s a question I often hear about, and the methods are not intuitive. In this post, I’ll show you several ways to accomplish this goal.
On Raspberry Pi OS, the easiest solution to start automatically a program on boot is to use the crontab with the @reboot event. There are also other methods using the Linux init systems.
So yes, it’s possible, but you’ll need to go with the solution that best fits your needs. You can choose to follow the “best practices” or just remember the simplest solution (that’s often my favorite). Let’s go!
If you’re new to Raspberry Pi or Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your Raspberry Pi. Click here to get it for free!
Methods to Run a Program at Startup
In this first part, I’ll go directly to the main point: how to start any script or program on boot.
For the example, I’ll use my test script which is in my home folder, so /home/pat/test.sh.
Don’t forget to make your script executable via user permissions.
You’ll need to change this line to the script or program you want to run. If you have no idea which command you need to input, read the second part of this guide :).
1 – Use Crontab
Cron is a service automatically started at boot which allows the user to run scheduled tasks.
Cron is used in autostart methods across many Linux distros. A crontab is a file that will allow us to list what we want to execute and when to start it, in a format understandable by the cron service.
The crontab has many settings to start a script at a specific time or schedule (daily, weekly, 3 times a month, etc.). I wrote another post about scheduling tasks that you can check out to learn more.
You can get answers from real experts in minutes.
Get help with your setup
The crontab also gives us the option to launch a program on boot, with the @reboot option.
This is our first solution to starting a program automatically, and it’s probably the easiest one to remember from this list.
Here’s how to launch a program at boot with crontab:
- Open a terminal.
- Open the crontab file:
crontab -e
If’s your first time in the crontab, you need to select an editor (press Enter for nano).
- You’ll start with an empty crontab file that looks like this:

- Add a line starting with @reboot, followed by the full path to your script, like this:
@reboot /home/pat/test.sh - Save and exit (CTRL+O, CTRL+X with nano).
(If you’re new to this, I have a guide that shows you the most important commands and shortcuts in Nano.)
Your command is now scheduled to launch at each boot.
Note: If you want to see task scheduling in action, I have a video lesson available just for community members. Join here to watch it directly! Becoming a member gives you access to 30+ other lessons for Raspberry Pi and comes with many other benefits.
2 – Put Your Script in /etc/init.d
The second solution you can use is to place your script in the /etc/init.d directory.
I generally prefer this method for something like a service (like for my firewall script, as explained here). As I mentioned earlier, it’s not the best practice if you want to respect the Linux guidelines, but it works :).
Bonus tip: If the terminal still feels confusing, I made a simple cheat sheet with 74 commands explained in plain English. You can grab it here for free..
However, there’s still a format to follow for it to work correctly on boot.
Here’s how to do this:
- Create a new file in /etc/init.d:
sudo nano /etc/init.d/myservice
Change the file name to make it explicit. - Paste these lines (for example):
#!/bin/bash
### BEGIN INIT INFO
# Provides: MyService
# Required-Start: $all
# Required-Stop:
# Default-Start: 5
# Default-Stop: 6
# Short-Description: Your service description
### END INIT INFO
touch /home/pat/myservice_test
- The comments at the beginning are mandatory to make it start on boot (runlevel 5).
Change the service name and description to explain what your script should do. - Save & exit (CTRL+X).
- Add the execution permission to your script:
sudo chmod +x /etc/init.d/myservice - Finally, tell the system to start it on boot by using this command:
sudo update-rc.d myservice defaults
That’s the minimum to make it work. The goal here is just to run a script on boot. Reboot to try. If all is correct, your script should run once every time you start your Raspberry Pi.
If you want to set this up more properly, you can add start, stop and restart options to your service. You can find a detailed documentation here if that’s what you want to do.
Tip: Command lines can be a pain to memorize. I put the essential Linux commands on a printable cheat sheet so you don't have to keep googling them. You can grab the PDF here if you want to save some time.
3 – Create a Systemd Service
The third option is to create a systemd service.
You might also like: Are you sure your Pi is secure? Here are 17 simple tips to protect it.
Some might consider this the most proper way. It lets you control your program using the ‘systemctl’ command, just like you would for other services like VNC, Nginx, or cloudflared. However, it does have a specific format you need to follow below.
Here’s how to create a systemd service that runs on startup:
- Create a file in /lib/systemd/system:
sudo nano /lib/systemd/system/mytest.service - Paste the following lines:
[Unit]
Description=MyService
After=multi-user.target
[Service]
Type=idle
ExecStart=/home/pat/test.sh
[Install]
WantedBy=multi-user.target
- Change ExecStart to the full path to your command, and Description to remember what it is.
- Save & exit (CTRL+X).
- Modify the service file’s permissions to match other system services:
sudo chmod 644 /lib/systemd/system/mytest.service - Finally, tell systemd to run it at boot:
sudo systemctl enable mytest.service
That’s all! When you reboot, your program should run after all key system services have started.
4 – Add a Line to /etc/rc.local
The rc.local file is a script intended for the system administrator (you!).
On boot, it’s one of the last things executed (at the end of the multi-user run level).
So, it’s exactly what you need to run a custom service.
Here is how to use it:
- Open the rc.local file.
sudo nano /etc/rc.local - Insert script or service just before the “exit 0” line
Something like this:
- Don’t forget the ampersand(&) symbol at the end, or it might not work!
- Save and exit (CTRL+X).
You’re done—there’s nothing else to do. You can reboot now to try it out if you want.
Note: On the newest Raspberry Pi OS (trixie), using rc.local is discouraged. However, it’s still possible using the method below.
Here’s how to do it on Trixie:
- Create the rc.local file:
sudo nano /etc/rc.local - Add the lines below:
(Don’t forget to replace the path below with your script.)!/bin/sh -e
/home/pat/test1.sh &
exit 0 - Save and exit (CTRL+X).
- Make the rc.local file executable:
sudo chmod +x /etc/rc.local
Stuck on this project? Ask me or other Pi users in the RaspberryTips Community. We help each other out and you'll get answers quick. Join and fix it together.
Finding the Command to Auto-Start
Before trying to auto-start a program on boot, you may need some help knowing exactly what to run.
Sadly, Raspberry Pi OS doesn’t include a tool to start apps on boot, so you’ll have to find the command that launches the program. In this section, I’ll go over three ways to find it.
Provide Your Script Path
If your goal is to run a script on boot, the command is easy to find: it’s the path to the script.
For example, let’s say you created a script that resides in /usr/local/bin with the name start_script.sh.
For it to run boot, make sure that your script is executable. You can add the permission with:chmod +x /usr/local/bin/start_script.sh
Now you can input this command into one of the solutions above to run on boot:/usr/local/bin/start_script.sh
Find the Executable
Bonus tip: If the terminal still feels confusing, I made a simple cheat sheet with 74 commands explained in plain English. You can grab it here for free..
A second option is to run an executable command on boot. This is an easy solution if you know exactly what you want to do. The only difficulty you might run into involves the path.
Each command (htop, nano, mail, etc.) is installed at a specific location on your system (/usr/local/bin, /usr/bin, etc.). Most system commands will run properly on boot even if you don’t specify a path.
But for some programs, like lesser-known GitHub projects or things like that (I’m thinking about Log2Ram for example), this is not the case. Instead, you have to provide the complete path.
If you have no idea where the executable location is, here are a few tips.
You can use the “which” command to find it:which <COMMAND>
Here’s an example:

Now that you’ve found the path, you can input “/usr/bin/php” in your autostart file.
You might also like: I tried to replace my main PC with a Pi 5, here's what happened.
If “which” didn’t work, the “find” command may be helpful to find a program:sudo find / -iname php
If you need more details about this, you should probably read my other article here: 3 Commands to Search For a File on Raspberry Pi (and find it!)
View the Menu Shortcut
My last method works for graphical programs that you run directly from the Raspberry Pi OS main menu. Since you can’t see the shortcut’s location, it’s difficult to find the executable file.
But there’s an easy way to locate it:
- Open the Pi menu > Preferences > Control Centre.
- Go to the Main Menu tab.
- This tool allows you to choose which shortcuts you want in the main menu.

- Find the application you want to start.
There are sorted in the same order as on the main menu, so browse through the categories. - Then click Edit Item on the right.
A window shows up with the launcher properties.
In the Command field, you can see the exact command used when you click on it in the main menu.
Now you have everything you need to apply one of the four solutions we discussed earlier.
If you need the path location, check my previous tip with the which command.
That’s it—you now know four ways to automatically start a program on boot. Choose your preferred solution depending on what your program is, or maybe just choose the method you remember most easily.
If you know of other methods, easier or not, I’d like to know about them. Please leave a message in the community.
You’re now ready to create your own scripts and program them to run on boot! If you need more help on the programming side of things, I have a few articles waiting for you:
- The 7 Best Text Editors for Programming on Raspberry Pi
- Should You Learn Linux or Python first?
- 15 Fun Raspberry Pi Projects to Experiment with Python
Not getting the same result?
Even when you follow every step, small differences in OS version, hardware or config can change the outcome. Instead of wasting time guessing, get help from people who have already fixed the same kind of issue.
- Get help on your exact issue
- Access step-by-step videos for tricky setups
- Browse the website without ads

Patrick,
Here I am again with a different problem!
I tried the Upstart method for x11vnc (server app to allow me to control my Pi from my Desktop).
I did:
sudo nano /etc/init/x11vnc
and set contents as:
description “x11vnc”
start on startup
task
exec x11vnc -gui tray-setpass -rfbport PROMPT -bg -o %%HOME/.x11vnc.log.%%VNCDISPLAY
The exec command’s parameter was obtained from the Main Editor’s Properties entry for x11vnc. I rebooted and x11vnc was not autostarted. I checked the Automatically Started Applications in Desktop Session Settings and there was no entry for x11vnc (there were other entries present e.g. xcompmgr). I’ve tried putting ” around the exec parameter but it made no difference. Interestingly when I installed the clipit package (for a clipboard manager), that was automatically created in the Automatically Started Applications and does start at startup.
i was wondering if these methods also apply to armbian on the orange pi. one would assume so, or at least some itteration of, seeing as they are both linux/debian-based. thanks for the refresher. sometimes even the simplest of things are lost to time and memory
Hello,
Yes, they probably work
Basically, on any Linux system it should work (or at least some of them)
Patrick
What about adding a line into bachrc?
I saw this in a youtube video and it seems to work. I know nothing about linux though and I have no idea how to stop it once it’s started in this way. In my case I’m starting a Python script that runs a webserver.
I forgot to add the line I added as an example:
sudo python3 /home/pi/webserver/app.pi
is it possible to start a GUI app (calibre)
I tried the above methods but still no success.
If anybody could guide me in the correct direction it would be immensely helpful.
Thanks