How to run a program on Raspberry Pi: A beginner’s guide

How to run a program on Raspberry Pi

The Raspberry Pi is a powerful yet compact computer that allows users to run various programs, from simple scripts to advanced applications. Whether you’re new to Raspberry Pi or looking for different ways to execute programs, this guide will walk you through the easiest methods to run software on your device.

1. Running a program using the terminal 

The Terminal (Command Line Interface) is one of the most common ways to run a program on Raspberry Pi, especially for scripts and software development.

How to Run a Python Script in Terminal:

If you have a Python script named my_script.py, follow these steps:

1. Open the Terminal (click on the black screen icon or press Ctrl + Alt + T).

2. Navigate to the folder where your script is located:

cd /home/pi/projects

3. Run the script using Python:

python3 my_script.py

Running a C or C++ Program:

1. Compile the program using gcc:

gcc my_program.c -o my_program

2. Run the compiled program:

./my_program

2. Running a program using the Graphical Interface (GUI)

If your Raspberry Pi has a desktop environment (like Raspberry Pi OS with a GUI), you can run programs the same way you would on a regular computer.

How to run a program from the desktop:

  • Open File Manager and navigate to the program or script.
  • Right-click the file and select “Open with”, then choose the appropriate program.
  • Alternatively, double-click the file if it has an associated application.

Launching Installed Applications:

  • Click on the Raspberry Pi Menu (top-left corner).
  • Navigate to Programming, Internet, Office, or other categories.
  • Click on the application you want to open.

Build Raspberry Pi solutions with us

3. Running a program automatically on startup

Sometimes, you might want a program to start automatically when the Raspberry Pi boots up, especially for IoT projects (see why IoT projects fail), servers, or automation tasks.

Method 1: Using cron (Recommended for Scripts & Programs)

1. Open the terminal and edit the crontab file:

crontab -e

2. Add this line at the bottom to run a Python script at boot:

@reboot python3 /home/pi/my_script.py &

3. Save and exit (Ctrl + X, then Y and Enter).

Method 2: Adding to rc.local (For System Services)

1. Open rc.local:

sudo nano /etc/rc.local

2. Before the exit 0 line, add:

python3 /home/pi/my_script.py &

3. Save and exit (Ctrl + X, Y, Enter).

4. Running a Program Remotely via SSH

If you’re running a headless Raspberry Pi (without a monitor), you can run programs remotely using SSH.

How to Run a Program via SSH:

1. Connect to your Raspberry Pi using SSH from another computer:

ssh pi@your-pi-ip-address

2. Navigate to the folder where your script is stored:

cd /home/pi/projects

3. Run the program just like you would in the Terminal:

python3 my_script.py

5. Running a Program in the Background

To run a program without keeping the Terminal open, use:

nohup python3 my_script.py &

This ensures that the script keeps running even after you log out.

Final thoughts on running a program in Raspberry Pi

Use the Terminal if you’re comfortable with command-line execution.
Use the GUI for graphical applications and easy access.
Use cron or rc.local if you need automation on startup.
Use SSH for remote execution.
Use nohup to keep programs running in the background.

Want to build a custom Raspberry Pi project?


At
DeepSea Developments, we specialize in building Raspberry Pi solutions for different sectors. We invite you to get in touch today to bring your Raspberry Pi project to life!

Do you have questions? Contact Us!

Related Posts

skills for product management

Best skills for product management

There are certain skills for product management that will ensure a product’s success. Product managers are responsible for making sure that products meet customer needs

DeepSea Developments at Sensors Converge

DeepSea Developments at Sensors Converge

Over 5,000 attendees. 275+ exhibitors and 100+ speakers. DeepSea Developments participated as an exhibitor. The perfect event for the design engineering community. The attendance and

Search
Search
Tell us about your project

Ready to bring your ideas to life? Look no further!

Erika Steel

Business Leader

Let's

Fill out the form to get your PoC Template and Prototyping costs guides

PoC template pdf