How to Fix (main:30677): Gtk-WARNING **: cannot open display: ?

ยท 189 words ยท 1 minute read

If you are facing this error (main:30677): Gtk-WARNING **: 05:40:47.665: cannot open display: just install Gtk+ development library, and set the display screen to 0.

Installing Gtk+ using Homebrew ๐Ÿ”—

If you are using a UNIX-like OS such as Mac OS X, or a Linux distribution. You can use Homebrew package manager to install Gtk+ as following.

brew install Gtk+

Install Gtk+ using apt ๐Ÿ”—

If you are using Debian, Ubuntu, Elementary OS, Linux Mint, .. You can use this command to install Gtk+.

sudo apt-get install libgtk-3-dev

Set DISPLAY Environment Variable ๐Ÿ”—

If the error persists, just run this command on terminal to set the display to the current display/monitor/screen.

export DISPLAY=":0"

If the display command fixed the error, add those lines into your .bashrc or .zshrc (according to what you are using).

if [[ -z "$DISPLAY" ]]
then
    DISPLAY=":0"
    export DISPLAY
fi

Use X11 XQuartz on Mac ๐Ÿ”—

If your application still showing the same error on Mac OS, just install XQuartz from here https://www.xquartz.org and restart. Your Gtk apps will work after that.

I hope this helps. Do you recommend reading this blog post? share it!

Share:
waffarx cash back