Enable rc.local in Ubuntu: Step-by-Step Guide
In Ubuntu, the rc.local file is disabled by default. If you need to enable and use the rc.local file, you can follow the steps below:
- Open the terminal and enter the following command to open the rc.local file for editing:
sudo nano /etc/rc.local
- Add the commands or scripts that you want to run automatically when the system starts in the rc.local file. For example, you can include the following:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
exit 0
- Save and exit the rc.local file. In the nano editor, press Ctrl+X, then press Y to confirm saving, and finally press Enter to confirm the file name.
- To grant execution permissions to the rc.local file, enter the following command:
sudo chmod +x /etc/rc.local
- Finally, restart the system to apply the changes by entering the following command:
sudo reboot
Afterwards, when the system starts up, the commands or scripts added in the rc.local file will be executed automatically.