Tuesday, June 7, 2016

Setup Chromebook for development

June 7th, 2016.
This how I set up my chromebook, I do some development work, mainly front end and quantitative programming. I share this because some of it is hard to find out. This page owes a lot to a sources, I mention them in the text. All the work on crouton is borowed from David Schneider, but there other sources as well.

Go into developer mode

Depends on the machine on the Asus chromebox depress the reset button (next to the Kensignton lock) and the start the machine, nex release the reset button. After that pres Ctrl-D at the prompt (there is no hint on the screen). A good source for developer mode is: http://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices

Install the crouton extension

Crouton is an easy way to get access to a full linux setup on your chromebook, you will find everything you need here: https://github.com/dnschneid/crouton
First install the crouton extension, this is for integration with your browser. You can get it by this link: crouton extension.

Setup crouton

Download crouton (it is a script). You can get it here: https://goo.gl/fd3zc
Install crouton via these commands:
shell
sudo sh ~/Downloads/crouton -r trusty -t core,xiwi,keyboard,x11,cli-extra,extension,xfce
After it runs you can enter the chroot with sudo enter-chroot, this will get you into Ubuntu.

Setup software in Ubuntu

This section is borrowed from this website: https://medium.com/@martinmalinda/ultimate-guide-for-web-development-on-chromebook-part-1-crouton-2ec2e6bb2a2d#.mdjctop47 however the setup for nodejs is not functional if you want to use gulp. I have changed that section in the part below.
This part of the set up is done in the chroot, see above.
You may, of course choose, what you want to install, this is just what I figured out and wanted to share.

Git

sudo apt-get install git
Using version control is quite essential.

NPM + NodeJS

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
Check your version with node -v, you can check you have the most recent on NodeJS.org.
For other nodejs versions, for example 0.12 use in stead:
curl -L http://deb.nodesource.com/setup_0.12 | sudo bash -
and then
sudo apt-get install nodejs
and then to compile and install native addons from npm you may also need to install build tools:
sudo apt-get install -y build-essential
To be able to install packages into global directory, we need to move it under home:
npm config set prefix '~/.npm-packages'
echo 'export PATH="$PATH:$HOME/.npm-packages/bin"' >> ~/.bashrc
//this should work now:
npm install -g bower grunt gulp ember-cli babel

Web starter kit

This is not really software the web starter kit from github on google/web-starter-kit is a template for web (apps). The dowload version of 0.6.3 does not seem to work well the cloned version does.
I found gulp with web starter kit (from google) does not run well with the latest gulp (3.9.1) so you may want to downgrade to 3.9.0. with
npm install -g gulp@3.9.0
This is a solution from Yeoman, see http://stackoverflow.com/questions/35832739/error-with-gulp-serve-requiring-external-module-babel-register/36475122#36475122

Sublime Text 3

Sublime is very popular, I am not a fan, I prefer Zed, a native app for chrome, you can get it here: https://chrome.google.com/webstore/detail/zed-code-editor/pfmjnmeipppmcebplngmhfkleiinphhp?utm_source=chrome-app-launcher
For sublime follow this section.
sudo apt-get install software-properties-common python-software-properties -y
sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer
At this it is reccomend installing Nautilus (a file browser) to get full support of gtk windowing system. Sublime fails to launch without it and on top of it, you get a GUI for file browsing. That maye be handy sometimes.
sudo apt-get install nautilus
Now you can launch Sublime with:
xiwi -t subl

Terminator

sudo apt-get install terminator
You can now launch terminator in a window with:
sudo xiwi -t terminator

Set up for virtual box

You may also want to run virtual box. I took these from the ubuntu/debian ppa for chromebook kernel headers. You can find it here: https://github.com/divx118/crouton-packages
Currently supported:
- Kernel 3.4.0 Architecture arm, i386 and am64 ==> These all need
testing.
- Kernel 3.8.11 Architecture arm, i386 and am64 ==> amd64 is
tested. i386 and arm needs testing.
- Kernel 3.10.18 Architecture arm
and amd64 ==> amd64 is tested. i386 and arm needs testing.
Open a crosh shell and follow on screen instructions:
cd ~/Downloads
wget https://raw.githubusercontent.com/divx118/crouton-packages/master/change-kernel-flags)
sudo sh ~/Downloads/change-kernel-flags
When running sudo sh ~/Downloads/change-kernel-flags -h it will give you the usage. You may want to revert the changes so put save a backup kernel use -r:
 sudo sh ~/Downloads/change-kernel-flags -r
Note: You will need to repeat the above steps after each chromeos update.
The following is done only once. Open a shell in your chroot:
cd ~
wget https://raw.githubusercontent.com/divx118/crouton-packages/master/setup-headers.sh

sudo sh setup-headers.sh
This script will: add a signing key with which the packages are signed, add the ppa to the sources.list.d install linux-headers-, install linux-image-, add a rc.local script to load vboxdrv modules on entering the chroot if they are available.
Kernel headers are build according to this guide https://github.com/dnschneid/crouton/wiki/Build-kernel-headers-and-install-Virtualbox-(x86) kernel headers for arm are cross compiled.
Now go ahead and install virtual box sudo apt-get install virtualbox

Install Rstudio

RStudio needs the latest r-base, not standard available in the ubuntu packages, so you need to add sources first. This method will use the latest development version of R-base from Michael Rutter.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 // wil add a key to your keyring
sudo add-apt-repository ppa:marutter/rdev

If you are met with the message: sudo: add-apt-repository: command not found. 
You can install it with 
sudo apt-get install software-properties-common
Then continue.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install r-base
After which you have r-base installed. You can now install R-studio if you like, download it from the Rstudio website and install using the debian package installer (in the GUI) if you have chosen the *.deb version.

Aliases

Aliases can save you a lot of time and energy. In your .bashrc add some lines, here is a few I use very frequently:
 alias cdd="cd ~/Downloads"
 alias x="xiwi -t"
 alias xw="xiwi -w"
There is also one handy alias that can allow you to get into chroot a bit faster. It has to be stored in .bashrc outside chroot:
echo 'alias ec="sudo enter-chroot"' >> ~/Downloads/.bashrc
And then leave chroot, and move it to the chronos home .bashrc:
logout
cat ~/Downloads/.bashrc >> ~/.bashrc
If you have just added these you need run source .bashrc to activate them.

Setup autostart on Chromebook

Move your crouton script and the backup into the Downloads directory on the machine (as well as all the keys and stuff). Specifically include crouton crouton.init crouton.conf and rw-rootfs.
After reboot run the file rw-rootfs (this is a script < see https://github.com/dnschneid/crouton/wiki/Autostart-crouton-chroot-at-ChromeOS-startup )
Run this file in the shell (not in the chroot)
like this: sudo sh ~/Downloads/rw-rootfs
It will reboot.
Next copy the crouton.conf file to /etc/init with this:
`sudo cp ~/Downloads/crouton.conf /etc/init/` 
Reboot and it will work. I use this to enter-chroot on startup

Backup and restore chroot

To backup your chroot use: sudo edit-chroot -b nameofchroot
To restore use sudo edit-chroot -r nameofchroot
You can delete a chroot by sudo edit-chroot -d evilchroot
In the event that you want to restore a backup to a stock chromebook (with developer mode enabled) you can use the crouton installer with the -f option specifying the backup’s tarball, e.g.,
sudo sh -e crouton -r raring -f /media/removable/SD\ Card/backup/raring-20130617-1234.tar.gz 

Update the software

When a new version of your chroot comes out you may want to upgrade.
Check for updates, download the latest version, and see what’s new by running croutonversion -u -d -c from the chroot (run croutonversion -h to see what those parameters actually do).
Exit the chroot and run sudo sh ~/Downloads/crouton -u -n chrootname. It will update all installed targets.

After an update of chomeos do

If you have virtual box installed, rerun the script to change the kernel flags. Open a crosh shell and follow on-screen instructions:
sudo sh ~/Downloads/change-kernel-flags
then reboot.
If you have set up autostart, rerun the file to make root writable this in the shell (not in the chroot)
like this: sudo sh ~/Downloads/rw-rootfs. It will reboot.
Next copy the crouton.conf file to /etc/init with this: sudo cp ~/Downloads/crouton.conf /etc/init/ if you have set up autostart.

2 comments:

  1. Just commenting based on RStudio. I have a Chromebook and it was a headache with Ubuntu. Recently though, I discovered IBM's Data Scientist Workbench has RStudio IDE among other tools for free that can be utilized in the cloud. Perfect for Chromebooks without having to jump through hoops in Ubuntu

    ReplyDelete
  2. I guess it depends on your needs. Running rstudio locally has advantages, like running the latest version and being independent of wifi. If you don't need that, then hosted rstudio is a good option. It was, however, not difficult to set up locally.

    ReplyDelete