Enable rc.local Startup Scripts on Ubuntu 16.04 and 18.04 with systemd
This guide shows how to configure rc.local‑style startup commands on Ubuntu 16.04 by editing /etc/rc.local directly, and on Ubuntu 18.04 by linking the systemd rc‑local.service, creating an executable rc.local file, adding shell commands, and verifying the result after reboot.
Ubuntu 16.04
On Ubuntu 16.04 you can still use the traditional /etc/rc.local script. Edit the file with a text editor such as vim /etc/rc.local and add the commands you want to run at boot. Ensure the script ends with exit 0 and is executable.
Ubuntu 18.04 – systemd transition
Ubuntu 18.04 replaces the old init system with systemd, which does not read /etc/rc.local automatically. To restore rc.local‑style behavior, follow these steps:
Link the rc‑local service file
ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.serviceInspect the service file cat /etc/systemd/system/rc-local.service The file contains sections [Unit] , [Service] , and [Install] that define when the service runs, how it starts, and how it is enabled. [Unit] – sets dependencies (e.g., After=network.target). [Service] – uses Type=forking, runs /etc/rc.local start, and sets TimeoutSec=0, RemainAfterExit=yes, GuessMainPID=no. [Install] – makes the service start on multi-user.target and provides an alias rc-local.service.
Create the rc.local file touch /etc/rc.local Make it executable chmod 755 /etc/rc.local Edit rc.local and add your commands
#!/bin/bash
echo "test rc " > /var/test.logEnsure the script ends with exit 0 so systemd knows the service finished successfully.
Enable and start the service
systemctl enable rc-local
systemctl start rc-localReboot and verify reboot After the system boots, check /var/test.log to confirm the command ran.
These steps provide a compatible way to run custom startup commands on both Ubuntu 16.04 (using the legacy init system) and Ubuntu 18.04 (using systemd). Remember to keep rc.local simple and idempotent, as it runs with root privileges at boot.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
