X11 Forwarding in Linux/Mac OS X – For Macs, your best option is to download xQuartz from xQuartz.org.This is free software which will allow you to forward X11 on a Mac. Download the xQuartz DMG, open it, and follow the installation instructions. From X11 (which runs side by side with Mac OS X’s native Aqua environment), you can run a host of graphical Unix programs—applications that haven’t been fully ported to Mac OS X—as well as.
Download X11 Mac
On MacOS X, XQuartz enables you to use the X11 window system.
1. Install XQuartz application
Here we provide two ways to install XQuartz application. You could either install from official website or install with Homebrew. In general, we recommend you to use Homebrew to install and manage packages on MacOS X.
- Download and install directly from XQuartz.
- Install with Homebrew. There are two steps: 1. Homebrew Cask is an extension of Homebrew. It installs GUI applications under the framework of Homebrew. Install Homebrew Cask with command
brew tap caskroom/cask
. 2. Install XQuartz with commandbrew cask install xquartz
.
2. Validate X11 installation on your Mac
Open XQuartz application from the launchpad on your Mac to see if it is installed correctly. It will open an xterm
window. If that does not work immediately, try restarting your computer.
3. Validate X11 connection to remote server
Next, try running an X11 application on one of the CS50 Unix servers. Log into a CS50 Unix server and launch an X11 application, such as xclock
or xemacs
. For a little fun, try xeyes
.
The -X
option to ssh
sets up X11 forwarding for ssh
connections. That is, it sets up a secure tunnel between the program (like xclock
) running on the server and the XQuartz application on your Mac; the program can create windows, buttons, menus, etc.; all the information flows through the ssh tunnel to XQuartz, which renders the windows on your Mac. It works with all CS50 Unix servers. xpdf
will open a pdf viewer in X windows system on your local computer. Here’s an xpdf window.
Note
A warning may show up saying $Home/.Xauthority does not exist
if it is your first time to use X11. The Xauthority
file will be configured automatically at the first run. From then on, the warning should not appear.
Download X11 For Mac Os X
Reference
Your first GTK+ application
If you need a GUI (graphical user interface), we recommend the gtk+
library, which is a popular UI toolkit for the X11 window system. There are two versions of gtk+
libraries: gtk+-2
(version 2) and gtk+-3
(version 3). gtk+-2
is still alive but we recommend the latest version, gtk+-3
. Both versions are ready to use on our CS50 Unix servers, so you need to specify the version to work with at compile time.
The gtk-example.c example program, below, uses gtk+-3
. It opens a window with a simple button, as shown below the code. Feel free to use!
Compiling with gtk+
Use the following command to compile gtk-example.c:
pkg-config --cflags gtk+-3.0
will produce a list of header paths you might use in your application and pkg-config --libs gtk+-3.0
will produce a list of library paths. (Notice the use of back-ticks for bash command substitution.) A more detailed explanation can be found in references below, which include a well-written tutorial.
Reference