How to Automatically Start a Script on Boot in Ubuntu

If you have a bash script that you need to run automatically every time your Ubuntu machine boots up, using a systemd service is the most robust method.

Creating a Systemd Service

  1. Create a new service file: sudo nano /etc/systemd/system/myscript.service.
  2. Add the execution instructions pointing to your script.
  3. Enable the service to run on boot: sudo systemctl enable myscript.service.
  4. Start the service immediately to test it: sudo systemctl start myscript.service.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.