Linux: Start an application automatically at boot

There are different methods for starting an application automatically every time a Linux system boots up. We will survey a few methods that work on Ubuntu and on Raspberry PI.

Use Cases

Different methods work best for different use cases. To choose the best method, consider how you need your application to run:

  • Under a graphical user interface or not?
  • As a user or as a system process (daemon)?
  • Does it require automatic restarting if it crashes?
  • On a headless server (no monitor or keyboard) or on a desktop workstation?
  • What operating system (Raspbian, Ubuntu, other)?

Ubuntu with a graphical user interface, User Specific

Tested on Ubuntu 16.04 and Ubuntu 20.04

This method is user-specific. The application will be launched when the specific user logs in.


Log in as the target user. Open a terminal window and type:


Alternatively, open Startup Applications via the Activities overview
A graphical user interface will show up. Click add. The rest is self-explanatory.
This will create a file, called a desktop item


where <name> is the name you gave the application in the step above.

Raspberry PI With a Graphical User Interface, User Specific

Edit the file:

Or on older Raspbian versions:

In that file, add a line to start each of your scripts:

@/usr/bin/python /home/pi/
@/usr/local/bin/electron /home/pi/

1. Don’t forget the @
2. Your commands should come before the @xscreensaver line.

Update for recent Raspbian distribution
The stretch image removed ~/.config/lxsession and it's content.


mkdir -p ~/.config/lxsession
cp -R /etc/xdg/lxsession/LXDE-pi ~/.config/lxsession

Raspberry PI With a Graphical User Interface, All Users

The instructions are the same as above but the locations of the files are:

Or on older Raspbian versions:

If the global file and the local file are both present, only the local file is executed.

An application that Requires no Graphical User Interface: Any Linux or Raspberry Pi Distribution, Single User

Method 1: Add a line to ~/.bashrc or
Method 2: Add a line to cron for each program:


@reboot /path/to/job | at now + 2 minutes
@reboot sleep 60 && /path/to/job
@reboot /path/to/job

System Process (daemon): Any Modern Linux and Raspberry Pi Distribution,

This method is for the case when you want to run your program as a system process, whether users are logged in or not. This also works with a headless server.

Historically there were 3 frameworks in the Linux world for controlling system processes. The historical SysV, the intermediate Upstart, and the new systemd. Today systemd is used almost everywhere, including RHEL7 or later, Ubuntu 16.04 or later, and recent Raspberry PI distributions. Below are instructions for systemd.

Create the following file and save it as


Replace <app-name> with the name you want to give your service.

File content:

Description=A description of my application



Change the Description and the ExecStart entries as needed.

Then enter the following commands at the shell:

sudo chmod 644 /lib/systemd/system/<app-name>.service
sudo systemctl enable <app-name>.service
sudo systemctl daemon-reload
sudo systemctl start <app-name>.service

This approach is very configurable. Adjusting the configuration allows control of the conditions when the application is launched, whether it restarts after it crashes and the order of execution relative to other processes.

Quick and Easy System Service on Linux and Raspberry Pi Distribution,

This use case is similar to the previous one but does not require as many steps. The downside is that there is no automatic restart after a crash and no precise control of the order of execution. Also, it is not supported by some modern distributions. Your program will start after all other programs have been initialized.


  • Ubuntu 16.04 — yes
  • Ubuntu 18.04 and later — No
  • Raspbian 10 — yes
  • Raspberry PI OS (buster)— yes

Edit the file /etc/rc.local

Add the following at the bottom:


Node.js application

To start a node.js application automatically, including restart upon a crash and also whenever the source code changes you can use the node forever library.

sudo npm install forever -g
sudo npm install forever-service -g
sudo forever-service install <my-application> -- script /path/to/my/script.js
sudo service <my-application> start

The following tools allow you to control the program:

sudo service <my-application> start
sudo service <my-application> stop
sudo service <my-application> status
sudo service <my-application> restart






Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

NEAR Hackathon Partners: Announcing Aurora

Flare-On 7 2020 Challenge #5: TKApp

Increase efficiency in data engineering using lean agile

Biz vs Dev — who is more important?

Techies’ meetup groups in Amsterdam

Group of people brainstorming ideas illustrated.

via Tumblr

Garden & Terraform: Your End-to-End Kubernetes Workflow

Curated By Carla — Issue #18 — The New Year Is Here!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Josh Sakov

Josh Sakov

More from Medium

Bash Scripting — Intro — Linode Linux Server — Simple Script

Using Linux Run Levels for VM termination tasks

Install and Configure Apache Web Server on Ubuntu 20.04

Git and Github — TechnoPals