× Toggle menu

Setup a X11 desktop on Codeanywhere

In this post we'll guide you on how to to run an X11 desktop on your Codeanywhere Container. This will give you a mechanism to develop and test native desktop applications from Codeanywhere.

Install the following packages:

$ sudo apt-get update
$ sudo apt-get install Xvfb
$ sudo apt-get install x11vnc
$ sudo apt-get install wm2 
$ sudo apt-get install scrot

Run an X server with a virtual frame buffer. I chose a small frame buffer with a visual depth of 16-bits but you could experiment with a larger frame buffer size and depth.

$ Xvfb :0 -ac -screen 0 800x600x16 &

We'll now run a very minimal window manager and xterm on the X server:

$ DISPLAY=:0 wm2 & 
$ DISPLAY=:0 xterm &

We can capture the virtual frame buffer to verify the X server is running:

$ DISPLAY=:0 scrot screen.png

File screen.png should appear in your File Explorer. Click on the file. A dialog stating that file is either binary or uses an unsupported text encoding and might might make the IDE unresponsive. Don't worry, just click Yes. Click the "Open Preview to the Side" icon in the top right corner of the tab. You should see a simple desktop with an xterm window.

Now run a VNC server associated with the X server:

$ x11vnc -nopw -localhost -display :0

Last thing we need to be able to connect from our local computer is to tunnel the remote x11vnc server port through a local port.
First add your private ssh key to your Codeanywhere Container's authorized keys list.

vi ~/.ssh/authorized_keys  

Insert your public into a new line. Usually the key is located on your local computer in the ~/.ssh/id_rsa.pub file. To get the key run:

cat ~/.ssh/id_rsa.pub  

If you don't have the public key, follow the instructions on how to generate an ssh keypair.

Now you should be able to connect to your Codeanywhere Container using ssh command:


You can find the {CONTAINER-DNS} and {CONTAINER-PORT} information on your "Getting Started" tab (in the Main Menu click Help -> Getting Started).

For example:

ssh cabox@host28.codeanyhost.com -p 59179  

When connecting for the first time, you might be asked to confirm the authenticity of host {CONTAINER-DNS}. Type yes and press Enter.

You should be now connected to the Codeanywhere Container. Type exit to get back to your local shell.

Now we can setup ssh tunnel:

ssh -L 5900:localhost:5900 cabox@{CONTAINER-DNS} -p {CONTAINER-PORT}  

Point a local VNC client to host "localhost" on port 5900 and you'll see your X11 desktop on the DevBox! I'm sure you'll find many interesting uses for this.

Ready to start coding from anywhere?

Join the growing community of over ... businesses and professionals that already use Codeanywhere on a daily basis, and you can start coding from anywhere for free.

Sign up for free