$DISPLAY is not set or cannot connect to the X server

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

Error:

$ startkde
$DISPLAY is not set or cannot connect to the X server.

Solution:
Do not use startkde directly. Use startx and configure it to startkde.

Make sure that X Windows is properly installed, configured and running.
Try:

$ startx
bash: startx: command not found

The result shows that X Windows is not properly installed.
Check your system installation guide to install X Server.

In you home directory, create a file named .xinitrc with this simple line:

exec startkde

https://wiki.gentoo.org/wiki/Xorg/Guide