Before systemd came into existence, most major Linux distributions ran a Sys-V style init system. Sys-V used seven different "runlevels" to determine which processes to start on the system. For example, runlevel 3 was typically reserved for the command line and its related programs, whereas runlevel 5 would launch a GUI and all the processes required for it. Results may vary, depending on the distro in question.

These days, the vast majority of Linux distros have adopted systemd as their init system. Some distros still use Sys-V, where the implementation of runlevels as described above still exists. On systemd systems, the concept of runlevels is still alive, but they have been adapted into systemd "targets."

Remnants of Sys-V still exist on some systems, where commands like runlevel still work. But some modern systemd distros have eradicated this support completely. In this guide, we'll show you how to check the current runlevel on Linux.

In this tutorial you will learn:
  • How to check the current runlevel
Checking the current runlevel on a Linux system
Checking the current runlevel on a Linux system
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro with Sys-V, and various distros with systemd
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Check current runlevel


SUBSCRIBE TO NEWSLETTER
Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


The following command can be used to view the current runlevel. This will only work on some systemd distros, but should work for any Sys-V system.

$ runlevel

Alternatively, you can run this command:

$ who -r
Checking the current runlevel on a Linux system
Checking the current runlevel on a Linux system

In the screenshot above, you can see that our system is currently in runlevel 5. This is a systemd distro, which means that the concept of runlevels are mostly kept around for compatibility. In reality, the various runlevels have been mapped to corresponding systemd targets. You can see this for yourself with the following command.

$ ls -l /lib/systemd/system/runlevel*
You can see here how systemd targets are mapped to Sys-V style runlevels
You can see here how systemd targets are mapped to Sys-V style runlevels

Like runlevels, there are 7 systemd targets by default. The two main targets are multi-user.target and graphical.target. You can see your system's default systemd target with the following command.

$ systemctl get-default
Determining the default systemd target
Determining the default systemd target

On our test system we're in graphical.target, which makes sense because we are running a GUI.



To see which services are mapped to this target, use the following command.

$ systemctl list-dependencies graphical.target
Checking the dependencies of the graphical.target in systemd
Checking the dependencies of the graphical.target in systemd

To see which systemd target (or runlevel) a service requires to run, try the following command. In this example, we'll check on the SSH service.

$ systemctl show -p WantedBy sshd.service
Checking to see which systemd target a service is assigned to
Checking to see which systemd target a service is assigned to

To disable or enable a particular service from starting up automatically on its assigned runlevel, you can use the following commands.

$ sudo systemctl enable sshd.service
OR
$ sudo systemctl disable sshd.service

On Sys-V init systems, you'd use the old chkconfig command, which doesn't work on modern systemd distros. For example, to run apache2 on runlevel 2, you will use this command:

# chkconfig apache2 2


Closing Thoughts

In this guide, we saw how to check the current runlevel of a Linux system. We also saw how the runlevel-related commands are just remnants of Sys-V, and only implemented on certain systemd distros as a means of backwards compatibility. Whether you're using systemd (most likely) or on a distro that uses Sys-V, the commands here will help you determine your runlevel and enable or disable processes from running in it.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.