Right after you install CentOS, you'll be able to access your system with the standard Linux login screen on a command-line prompt. If you want to access to a GUI, you need to do the following:
- Be sure to have it installed.
- Log-in, then type the following command: startx
In case you don't have a Graphical Environment installed, you can easily fix that by installing GNOME with the following shell commands:
1 |
yum groupinstall "GNOME Desktop" "Graphical Administration Tools" |
It's worth noting that manually issuing the startx command will launch the GUI just for that specific session: in other words, it's a one-time fix and won't change the log in process for future logins.
To set up your system so that the GUI will be launched upon each login automatically, you need to do the following:
CentOS 6.x and earlier
- Open the /etc/inittab file.
- Change the runlevel option from 1 (or 3) to 5.
The /etc/inittab file tells init which runlevel to start the system at and describes the processes to be run at each runlevel. An entry in the inittab file has the following format:
1 |
id:runlevels:action:process |
Here's a list of all the available runlevels values:
1 2 3 4 5 6 7 |
0 - halt 1 - Single user mode 2 - Multiuser, without NFS (The same as 3, if you don't have networking) 3 - Full multiuser mode 4 - unused 5 - X11 6 - Reboot |
You can alter the etc/inittab file with the text-editor you like: for example, you can do
1 |
gedit /etc/inittab |
or
1 |
vi /etc/inittab |
CentOS 7.x and later
With the introduction of systemd, the file /etc/inittab is no longer used to set the default run level: the new /etc/inittab file became nothing more than a readme containing a short (and useful) guide to the new target-based system:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# inittab is no longer used when using systemd. # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target # # systemd uses 'targets' instead of runlevels. By default, there are two main targets: # # multi-user.target: analogous to runlevel 3 # graphical.target: analogous to runlevel 5 # # To view current default target, run: # systemctl get-default # # To set a default target, run: # systemctl set-default TARGET.target |
That pretty much summarizes what we have to do to enable the GUI on boot.
Open a shell command-prompt and type the following:
1 |
systemctl set-default graphical.target |
This sets the default runlevel to 5, which is multiuser with auto-loading the Graphics Environment on boot / startup sequence.
You can try these new settings with a reboot, which should prompt you with something similar to the following screenshot (if you're using GNOME):
That's about it: happy GUI!