To restart Ubuntu server immediately, you can use the reboot command:
sudo reboot now
I primarily use Ubuntu on almost all of my cloud services be it DigitalOcean or Linode. For a long time, I used Ubuntu as my desktop OS. The familiarity with the APT package manager made me more comfortable with Ubuntu as a server.
I am trying to share my experience with the server side on Linux Handbook, be it quick tip or a complicated task. This is a quick one where I am going to show you how to restart Ubuntu server in the terminal.
How to restart Ubuntu server
Since restarting a server is a critical task from functional point of view, only admin users can perform it. In other words, you need to have super user rights or use sudo in order to run the commands to restart or power off the system.
1. Use reboot command
If you want to restart Ubuntu server immediately, you can use this command:
sudo reboot now
If you don’t use the ‘now’ in the above command, it will reboot the system after a delay of one minute.
If for some reasons, your Ubuntu server is not restarting, you can try to force a reboot with option -f.
sudo reboot -f
2. Use shutdown command
There are other ways as well. My preferred way is using the shutdown command in Linux. With the option -r, the shutdown command will reboot the system instead of just shutting down.
sudo shutdown -r now
Instead of the now, you can give it a timestamp. 0 means immediate shutdown/reboot. You can also use the -H option that stands for halt. With this option, the system will first terminate all the processes and then shut down the CPU.
sudo shutdown -r -H +0
3. Use systemd command
Ubuntu uses systemd so you can also use systemd specific command for rebooting your server:
sudo systemctl reboot
There could be several other ways but these three commands are easy to remember. So, the next time you need to restart Ubuntu server, you can do so easily without even looking up on the internet.