How to boot Linux to command-line mode instead of GUI?

Update for RedHat/CentOS 7 that has switched from sysvinit to systemd.

To switch from GUI to CLI: systemctl isolate multi-user.target

To switch from CLI to GUI: systemctl isolate graphical.target

To set the CLI as a default runlevel (target in systemd terminology): systemctl set-default multi-user.target. Analogously for GUI: systemctl set-default graphical.target

*CLI = Command Line Interface = command-line mode


Update: The answer below is now obsolete

For a lot of distros now, the default is systemd rather than sysvinit. The answer below was written with sysvinit in mind. The more-up-to-date answer (and the one you should use if you have systemd as your init system) is golem's answer.

sysvinit answer (obsolete on most current distros):

You want to make runlevel 3 your default runlevel. From a terminal, switch to root and do the following:

[user@host]$ su
Password:
[root@host]# cp /etc/inittab /etc/inittab.bak #Make a backup copy of /etc/inittab
[root@host]# sed -i 's/id:5:initdefault:/id:3:initdefault:/' /etc/inittab #Make runlevel 3 your default runlevel

Anything after (and including) the second # on each line is a comment for you, you don't need to type it into the terminal.

See the Wikipedia page on runlevels for more information.

Explanation of sed command

  • The sed command is a stream editor (hence the name), you use it to manipulate streams of data, usually through regular expressions.
  • Here, we're telling sed to replace the pattern id:5:initdefault: with the pattern id:3:initdefault: in the file /etc/inittab, which is the file that controls your runlevles. The general syntax for a sed search and replace is s/pattern/replacement_pattern/.
  • The -i option tells sed to apply the modifications in place. If this were not present, sed would have outputted the resulting file (after substitution) to the terminal (more generally to standard output).

Update

To switch back to text mode, simply press CTRL+ALT+F1. This will not stop your graphical session, it will simply switch you back to the terminal you logged in at. You can switch back to the graphical session with CTRL+ALT+F7.


First switch user to root.

su -
Password:

Enter root password.

Use your favorite editor to modify this line in /etc/inittab:

id:5:initdefault:

Change the 5 to 3. When you (re)boot the computer it will take you to the command line rather than to the GUI.