Chrome OS native development
Posted on September 13, 2017 by Paul
Today is the third day of my Two weeks programming on a Chromebook challenge. For the first two days I’ve played with enabling the Developer Mode on my Chromebook and installing Crouton and GCC 7 for C++17 development. Running Chrome OS and Crouton side by side is the easiest path for a complete Unix like development experience.
I think it could be interesting and more challenging for me personally, to investigate if I could do native Chrome OS development. By native I mean using only applications that run directly on Chrome OS or can be compiled to run on Chrome OS. Using a separate OS is not an option!
I assume that you start with a fresh Chromebook and Developer Mode enabled. If you need more information about enabling the Developer Mode see the first article from this series.
Chrome OS is Linux under the hood so, in principle, you can run any standalone Linux binary on it. More precisely, Chrome OS is based on Gentoo Linux. By default, after you enable the Developer Mode, you have access to a limited set of command line utilities, honorable mentions here for the Bash shell and the Vim editor.
You can also install a limited set of development tools by running dev_install in a shell tab. Read the relevant documentation if you want to know more. Running dev-install for example, will allow you to use Python 2.7 on Chrome OS. Unfortunately, at the time of this writing, dev_install does not provide a compiler toolchain. My suggestion is to not use it, at least for now.
A good approach, for native Chrome OS development, is to install the compiler toolchain from Chromebrew. Open a shell tab and install Chromebrew with:
Next, let’s install a compiler toolchain with:
Check the version of GCC installed with:
An interesting problem appears if you compile a C or C++ program in your home folder and try to run the executable. By default, Chrome OS marks /home/chronos/user/ as noexec, so you will get a Permission denied error. AFAIK, there are two solutions. You can copy the executable to /usr/local/ or /usr/local/bin/. Alternatively, you can mark /home/chronos/user as exec with:
If you want to make your home directory exec permanent, save the above line at the end of your .bashrc file.
At this point, you should be able to install other packages from Chromebrew, using crew install. If a certain package is not available, you can built it from source with the usual configure, make, make install.
For example, you can install a newer version of Vim with:
As a short example, I will show you how to build from sources a command line utility, rlwrap:
Please note that the line autoreconf –install is typically not required. For this particular case, we’ve used autoreconf to generate a configure file. Usually, all you need to do is configure, make, make install.
rlwrap is useful if you have a tool that was not compiled with support for using the arrow keys to get access to the last command. E.g., python from Chromebrew will be more user friendly if you start it with:
instead of the usual:
As I’ve mentioned before, you can use, in principle, any self contained Linux binary. For example, you can install the latest version of Go and use it on your Chromebook, see the wiki. The official Go binary is usually newer than the one provided by Chromebrew.
If you intend to do Java development on your Chromebook, Oracle provides stand alone Linux binaries for JDK. As a side note, if you want to be able to use a Java IDE locally, check my previous article. You will need Crouton and a desktop environment in order to run an IDE. For the current article, I assume that you need to use java and javac exclusively from the shell.
Start by downloading the proper JDK for your system, typically the Linux x64 version. Be sure to select the file ending in .tar.gz option and not .rpm. Next, we can extract the archive with:
Please note that the version number from the above command may be different in your case. After the extraction, you should have a new folder, something like jdk1.8.0_144. Next, we can move it to /usr/local
Add Java to your path by writing the next two lines at the end of your .bashrc file:
After you’ve saved .bashrc, don’t forget to enable the changes:
or, simply close and reopen the shell tab.
Test if the Java compiler is available in your path:
If you want to learn more about the Linux command-line applications, I would recommend reading The Linux Command Line by William E.Shotts Jr.