Using a Chromebook for Web Development
Posted byon under
Have you seen anybody using a Chromebook yet? These are slim, lightweight laptops that run ChromeOS, an operating system made by Google that is designed around the Chrome web browser. If you want a laptop that you can use for doing your email, watching Netflix and other tasks you can easily do in a web browser, then a Chromebook is a very good choice, and also cheap, since most models are in the $150-$300 price range.
They also make great travel laptops if you are going on vacation or to a conference. The problem for me is that when I travel, I spend a fair amount of time coding (this is an addiction I do not want to get rid of!). So I decided to buy one and try to configure it in a way that is suitable for web development on the move. In this article I'm going to go over three different approaches to do that. (December 2018 update: there is now a fourth way that I will cover in a new article).
Chromebooks are fairly underpowered devices. There are low-end models with ARM CPUs, and mid and high-end models with Intel or Intel-compatible CPUs. If you plan on doing coding, I would recommend you only look at the Intel based ones.
In terms of RAM, most models come with either 2GB or 4GB. I think 4GB is an absolute minimum for doing any kind of development work, so when I did my research I have ignored any models with less than 4GB of RAM. There are high-end Chromebooks with 8GB and 16GB RAM, but these are all priced above $500, so in that price range you might as well get a Windows or Linux laptop.
The low and mid-level Chromebooks offer 8GB, 16GB or 32GB SSD storage, and usually have a micro-SD slot so that you can add more. Given that you always have the option to add more storage, the amount of internal storage was not a huge concern for me.
The model that I ended up choosing is the Samsung Chromebook 3. There are several variants all with this name, which makes picking the right model tricky. I chose one that comes with a dual-core Intel Celeron CPU and 4GB of RAM, because in this price range that is the best you can get these days. In case you are curious, I paid $179 USD for mine.
Chromebooks as Cloud-Based Laptops
Right from the start you notice that Chromebooks are nothing like regular laptops. The very first thing you have to do is enter your Wi-Fi connection details, and once you do that you get a login prompt and the machine is ready for you. No need to go through long set ups where you have to answer a lot of questions, set up a user account, etc. All you need to use a Chromebook is a Google account.
Once you log in, a Chrome browser opens and that is it, you can start browsing the web. If you want to check your email, you use Gmail. Write a report or spreadsheet? Google Docs. Presentation? Google Slides. Other types of files? Google Drive. You can certainly work while you are offline and use the local storage, but in general you have to be comfortable using cloud storage, because the Chromebook is designed under the premise that you will sync everything to the cloud.
The operating system that powers the Chromebook, ChromeOS, was built as a very secure platform that is more in line with "app store" concept, in which applications can only be obtained from an approved source, in this case the Chrome App Store, and for some models that support Android apps, also the Android Play Store.
As I'm sure you can guess by now, this isn't a platform that is friendly to coding. It feels more like having a tablet with a keyboard than a machine you can develop on. If you want to install the kind of software that we developers use, like for example, vim, a Python interpreter, etc., you have to resort to tricks. There are actually three different approaches that give you access to a Linux environment in which you can write code, all with pros and cons.
The Safe Approach: Termux
This approach is fairly benign, but is limited to Chromebook models that have support for running Android apps, which are those in this list. Some models support Android apps directly, while others need to be switched to the "beta channel", which installs a newer version of ChromeOS with additional features. The Samsung Chromebook that I'm using needs to be put on the beta channel to support Android apps.
The solution is based on installing a very cool Android app called Termux. Termux implements a user-mode Linux environment that can run on any Android device. The environment runs in a sandbox and does not require a rooted device, so the system security is not compromised in any way. Termux runs in its own window, and you can still use the Chrome browser or any other apps you have installed, so the integration is really good.
Termux has a few shell options such as bash and zsh, and comes with its own package manager based on Ubuntu's apt, which you can use to install your typical applications, including ssh, git, vim, Python, Node.js, nginx, etc. The list of packages that are supported is fairly extensive, you'll probably find that all the tools that you use have already been ported.
This seems like a perfect solution, right? Well, I have tried this approach and unfortunately it sounds better on paper than in reality. Because you are in a heavily guarded sandbox, the sharing between the Linux environment and the rest of the system is very limited, and this gets in the way. Examples:
- The files that you write inside the Linux file system are not visible from the outside. The only exceptions are a few system directories that Termux exposes to the Linux environment as mounts. For example, the Chromebook's
Downloadsdirectory is accessible from inside the sandbox, so it is an ideal place to store your projects, since that makes them visible from the outside and opens the door to using a Chrome based text editor or IDE. This mostly works, but because the device is not rooted, symlinks are not allowed on any of these system mounts. Since Python virtual environments create symlinks, you are forced to create your projects in the shared folders and your virtualenvs in internal folders, which is not how I'm used to organize my projects.
- Only command-line apps are supported, no GUI apps.
- No access to the Chromebook's hardware, such as the camera or the microphone.
- This is more an annoyance than anything else, but if you start a web server listening on localhost, the Chrome web browser will not be able to connect to it, because the Linux environment runs on a separate network so its localhost is not the same as the Chromebook's. The only way to access a web server from outside the sandbox is by having the server listen on the public network interface (i.e.
0.0.0.0) and then use the IP address Termux assigned to the Linux environment in the Chrome address bar, which you can obtain by running the
ip addr listcommand.
After I tried this approach and found no comfortable way to set things up, I looked at how other people implemented a solution based on Termux, and all have weird ways in which they attempt to bypass the strict security measures of the host operating system. Now don't get me wrong, I think you can create a decent environment, but it is not going to be a "familiar" environment, you will have to carefully design your workflow so that it does not collide with the restrictions imposed by ChromeOS.
But as a big plus for this approach, this is the only option that I know that can be implemented without root access, which is amazing considering how much you can get done while keeping the system secured. (Note that this statement is now outdated, there is a much better way to run Linux on your Chromebook without having to root your device).
If you are willing to sacrifice some of the tight security measures that ChromeOS implements, then you have more (and in my opinion better) options. If you are concerned about making your system less secure, consider that we are talking about making your system's security be on par with a regular laptop. If you bought a Chromebook because of its highly regarded security aspects though, I would recommend that you stick to the Termux solution I described in the previous section.
Chromebooks have a developer mode, intended for ChromeOS developers to have more freedom to access the system, obviously at the cost of reduced security. Developer mode disables internal verifications to detect infiltrated code every time the system boots. It also gives you shell access to the
chronos user, which is the default user in the system, a user that is configured with password-less sudo access by default.
Not checking the OS for infiltrated code is something I can live with. A system with password-less sudo I cannot. Let's first see how to switch the Chromebook into developer mode, then we'll address the sudo problem. Note that switching to developer mode requires a full reset of your system, so any files you have in local storage will be lost.
- Turn the Chromebook on while holding the
- A screen that reads "Chrome OS is missing or damaged" will appear. It looks scary, but it is expected. Press Ctrl-D to continue with the process.
- The next screen will say "To turn verification off, press Enter". When you press Enter, the system will do a full reset. This will take about 15-20 minutes.
- After the system resets, you will see a "System verification is OFF, press Space to re-enable". DO NOT press space! Press Ctrl-D to continue with the boot process.
After the above steps, ChromeOS will run as usual, but developer mode will be activated. Note that each time you boot, you will see the "System verification is OFF" screen, and you will have to accept it by pressing Ctrl-D. If you press Space by accident, developer mode will be deactivated and the system restored to factory settings. Anything in local storage will disappear.
You will not notice any difference in how ChromeOS operates in development mode. The hidden power is in the shell access, which is available by pressing Ctrl-Alt-T to open a crosh tab (Chrome Shell), and then typing
shell at the crosh command prompt.
As I mentioned earlier, this gives you full sudo access without password. The very first thing you need to do is recover some of the lost security by setting a password:
$ sudo chromeos-setdevpasswd Password: <type-your-password> Verifying - Password: <type-password-again>
At this point you have a system that is about as secure as a laptop or desktop computer, so we can stop worrying about security and see what cool things this developer shell can do. The next sections describe two different approaches to get a real Linux distribution installed on your Chromebook.
Dual-boot a Linux distribution
With the help of the chrx project, you can dual-boot your Chromebook between ChromeOS and a Linux distribution. This option leaves you with a full Linux installation that is running on a x86-64 CPU, so you can think of it as being equal to running Linux on a low-end laptop.
The installation process is pretty much automated. You need to open the developer shell as indicated above, and then download and run the chrx installer script:
$ curl -Os https://chrx.org/go && sh go
The script will ask you a few questions and then run for a while. When running without arguments as above, chrx will install GalliumOS, a small and beautiful Linux distribution based on Xubuntu, specially optimized to run on Chromebooks. If you prefer a different distribution, add
-d DISTRIBUTION to the
go command. Valid options are
There isn't really much to say about this option, as anything that runs on a regular Linux machine will likely run in the Chromebook as well, including GUI applications, containers, virtualization, access to camera and microphone, and anything else you can think of.
Run Linux inside ChromeOS
The only reason you may not want to go with the solution presented in the previous section is that you have to choose wether you want to boot ChromeOS or Linux, you cannot have both at the same time. And if you like the sleekness and simplicity of ChromeOS, it may be tough to get used to a less polished and harder to use Linux desktop.
If that is your situation, you may like the Termux solution more, because it nicely integrates into ChromeOS by creating a Linux terminal in a window. If you like the convenience of the Termux solution, but do not like the many limitations of running Linux in that environment, then you should definitely check out crouton.
Crouton is another installer script that runs on the developer shell like chrx, but it does something completely different. Instead of installing a fully independent OS, it creates a Linux chroot within ChromeOS. A chroot is like a poor man's Docker container, it is a much older technology that allows you to run processes in the context of a different file system root directory, hence the name "(ch)ange root". If you install a base Linux system in a subdirectory on your disk, chroot allows you to launch processes that see that subdirectory with all its contents as their whole file system.
The great benefit is that you can run one or more chroots in your system and the processes that live in each one are isolated from the others and from the processes in the host system. The downside is that the chroots do not run their own kernel, the kernel is always the one from the host system, in this case ChromeOS, so if your needs require working with specific kernels, or adding custom kernel modules, then this is not for you.
Like chrx, installation is fairly easy. First you download the crouton script from its GitHub repository, and then run it from a developer shell. For example, you can install Ubuntu 16.04 with the xfce and xiwi window managers with the command:
$ sudo sh ~/Downloads/crouton -t xfce,xiwi
The command line arguments allow you to specify what do you want to put in the chroot, with a few Debian, Kali and Ubuntu releases as choices (Ubuntu 16.04 is the default and most tested distribution). In addition to picking the OS, you can select what window manager you want to use, and these include the usual suspects: gnome, kde, unity, xfce, etc., and a special one called "xiwi" (X in a Window), that makes it possible to launch GUI applications in a ChromeOS window, or also in a browser tab. Other options allow you to encrypt the chroot for added security or restore a chroot from a previously made backup.
When you have a chroot created, you have a a few options. If all you want is command-line access, then right from a developer shell you can open a shell in the chroot with the
sudo enter-chroot command. You can also start a full-screen session using the window manager of your choice with
sudo start<window-manager>, so for example, this would be
sudo startunity, etc. depending on what window manager you installed. This will create a second full-screen window that is managed by the chroot, and you can switch back and forth between ChromeOS and the chroot with Ctrl-Alt-⇨ and Ctrl-Alt-⇦.
The most interesting option, however, is the xiwi window manager that I mentioned above. This is a custom manager that uses a memory buffer as display. You install the Crouton integration extension in the Chrome browser, and then for each window that you start in the chroot, the extension opens a new window or tab within the ChromeOS desktop, and displays the xiwi RAM-based display on it. The refresh rate prevents this solution from being usable to play games or any kind of application that requires low latency display updates, but for code editing it is perfect. For example, running
sudo startxiwi -T code starts Visual Studio Code in a Chrome tab. Below you can see a screenshot of this IDE open on a Python project.
I have been able to work with git, vscode, vim, zsh, tmux, Python, Flask, opencv without a problem. And unlike the weird networking in Termux, the localhost in a chroot maps to the localhost in the host operating system, so for example, you can run a Flask server in a chroot session and open it in Chrome at
localhost:5000, exactly like I would on my Mac or Windows computers.
As far as downsides, I haven't really found anything that is a deal killer yet. I found that Docker does not install in the chroot, but rkt does, so that's a good compromise solution to run containers (you can only use host networking though). Obviously you will not be able to run VirtualBox or anything like it. The key mappings take some time to get used to, I need to investigate how they can be improved.
So there you have it, three ways to run Linux on a Chromebook. After playing with all three, I decided I'm going to go with Crouton for the time being. This is the most polished approach of all that I have described, because I can run ChromeOS in all its beauty and have the choice to start terminals or graphical apps as standalone windows or tabs, with ChromeOS and Linux apps happily coexisting in the same desktop, and even in the same browser window.
But with a Chromebook nothing is permanent, since it is super easy to reset it back to a pristine state and start over with a different approach Do you use a Chromebook? Let me know in the comments if you have a great coding workflow.
December 2018 update: There is now a fourth way to run Linux on a Chromebook that is fairly similar to Crouton, but is officially supported by Google, and does not require putting the system in developer mode.
Become a Patron!
Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!
#26 Miguel Grinberg said 2018-03-04T16:35:27Z
@Stacey: Thanks, glad to see X packages are possible with termux now, unofficially at least.
#27 al krinker said 2018-06-22T14:31:00Z
Still going strong? or felt apart?
#28 Miguel Grinberg said 2018-06-22T18:09:17Z
#29 Light Coder said 2018-07-20T02:21:32Z
Just wondering - as I don't have a clue - is it "new" since you wrote this that Termux has been granted access to external storage? I'm hoping so?
I bought a Chromebook just to goof around - and the limits of my knowledge about the backend are basically limited to "type this into the terminal and there you go" ;)
All I need is localhost or a set IP - I toss my PHP scripts and LESS files in there, and I'm good to go - for instance, grab a copy of bootstrap, toss it in a directory, rename the directory, and start "developing" the new site.
I pray you'll update - or write a new article - if it ever becomes viable to manage that within termux? Heck, I wouldn't even know how to begin to do that with a linux distro. It's all built into my Mac - with the exception of the less to css processor. And, again, activating that was incredibly simple.
Anyway, the dream with the cheap chromebook (I got the Asus kiddy one with the bumper that can be dropped in water), was to just toss it in my Jeep with the top down and roll. Was hoping to hit the Appalachian trail again this fall - maybe even toss a cheap tablet in my backpack ;)
Thanks very much for the awesome write-up!
#30 Miguel Grinberg said 2018-07-20T03:10:41Z
@Light: As far as I know, Termux continues to have the same sandbox limitations as when I wrote this article. The other options I mention here are better if you are going to do serious development work on your Chromebook, in my opinion.
#31 Light Coder said 2018-07-22T08:18:41Z
As other folks might also run into the same issues - David was cool enough to respond to my difficulty installing Linux with crouton as a noob, and directed me to Robby's incredibly helpful video and write-up:
I dunno if the link is worth mentioning in your article - but whereas the instructions here, in the readme, and everywhere else repeatedly had me testing how "kid proof" my chromebook actually is - yeah, I tossed it pretty hard, a few times, after the 2nd and 3rd fails ;) -
Robby's instructions finally got me on the good foot with a working install via crouton. He also has his own glitches - and is very chill in explaining how to get around any problems.
#32 Marco said 2019-12-30T17:46:33Z
Just a quick tipp: If you like VS Code. Check out Theia IDE. I run it as a docker container on my VPS. Over there are my Python Bots, Websites, Web Applications. I can just mount the directory into the Theia IDE Docker Container und use VS Code in the Browser from anywhere in the World. No need of crouton here.
#33 Matteo Morreale said 2021-02-08T09:32:48Z
Just as an update to the main theme: now you can actually install Visual Studio as a Linux app, with no problem at all and you don't need GalliumOS :)
#34 Miguel Grinberg said 2021-02-08T15:45:46Z
@Matteo: this has been possible for a while. I have written a follow-up to this article that covers the Linux support in ChromeOS: https://blog.miguelgrinberg.com/post/coding-on-a-chromebook-revisited.