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:
yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
It’s worth nothing that manually issuing thestartx 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:
Here’s a list of all the available runlevels values:
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
CentOS 7.x and later
Within Oracle Linux 7 introduction of systemd the file
Within Oracle Linux 7 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:
# 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:
systemctl set-default graphical.target
This sets the default runlevel to 5, which is multiuser with auto-loading theGraphics 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!