RE: Microsoft Surface with Rails
the world beyond mac os x #3
I’ve not used Windows for work in about 14 years, I mean; on my work I’m forced to use it, but I basically use it as a dumb terminal since I’m running the actual software on linux (or probably I’m telling this to myself to avoid the truth).
you will deny me three times before using windows — Ozipi
For my surprise Microsoft changed in the last years, Windows 10 came out with a lot of fresh ideas (hybrid mode, fluent design), they admitted failure on the Mobile (but the UI of the windows mobile excellent) and most important they somehow started a new relationship with Linux, that reflects a big change of direction and from the public news I’m willing to give all the credit to Mr. Nadella, not without taking the opportunity to remind everyone that the previous CEO took Microsoft to weird places.
So after researching and not willing to take the risk of spending > ~1k on a gamble I decided to take a small step and I got a 10" edition of the Surface 3 for a great deal at newegg. I know it’s not a power horse, but I’m willing to trade performance for small factor. And also to prove another point; Apple is ignoring the people that wants 10" laptops. Their idea is that the iPad Pro should fill that space and Apple is wrong here. The Surface 3 it’s an excellent on-the-go computer, the build quality it’s on a pair of the MBP and for this price I got backlit keyboard and a Pen. And the pen is awesome, probably outside the scope but you will see that the screenshot feature is useful.
TL;DR Linux on Windows
Lets talk business; the whole idea of giving Windows a second change comes from a new component called Windows Subsystem for Linux, in non-marketing words is a compatibility layer for windows that allows the execution of ELF binaries without changes. The key things is that is lighter than a virtual machine and it allows some kind of direct access of a file system. I’m not going to give an overview on how this works, Microsoft already has an excellent blog with all the bloody details here. I’m going to talk from the perspective of doing real work around a basic premise:
All these linux support is still BETA
So expect glitches and workarounds.
Step 1: Get into the insider builds: I recommend you go SLOW
I tried the fast channel at the beginning but it was still buggy on the “sleep” so I quickly rolled back and changed to the slow channel, for my purposes is better. You basically have to open the “settings” app, go to updates and the last option will be “Windows insider program”

You can get more info here but its pretty straightforward. Go to “windows update” and you can force the download.
Step 2: Enable The Windows Subsystem for Linux (Beta)
On the search bar type “windows features” there scroll at the bottom, search for Windows Subsystem for Linux.

Step 3: Install Ubuntu from the Windows Store
Yes; just go to the windows store and get it from there;

Step 4: apt-get update
You know the drill, we need the basics to get rails, first do the update, then some basics to build
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-devGet rbenv, install ruby, ruby building takes a lot, don’t worry is normal
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
rbenv install 2.4.0
rbenv global 2.4.0
ruby -v
You need a javascript runtime for coffescript and the asset pipeline, so better get node before rails
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejsTime to make a decision; I run into problems while trying to install postgres on ubuntu, so at the end I fallback and I installed it on windows. On my case I just installed enough to compile the pg gem.
sudo apt-get install libpq-dev postgresql-client postgresql-client-commonThe trick here is that you need to make it connect via a tcp/ip port and don’t let the pg gem try to connect via unix socket in order to do that you have to use 127.0.0.1 instead of localhost. This is part of my database.yml configuration
default: &default adapter: postgresql pool: 5 timeout: 5000 host: 127.0.0.1 username: polographer password:
Time to get bundler;
gem install bundlerI steal a lot of commands related to the rails installation from this excellent gorails tutorial “Setup Ruby On Rails on Windows 10”
Step 5: Make a shortcut to your windows home on linux … wait, WHAT?
I’m going to say it on plain English NEVER NEVER NEVER EDIT A LINUX FILE DIRECTLY ON AN WINDOWS APP. Long story short, the metadata will be lost (permissions, sticky bits, etc) and it will render the file useless for linux. For more information here.
So here is the trick; you create a directory on your windows home in windows, and on /mnt/c you have access to your hard drive. That will allow both environments to be able to edit a file without messing the other one. And also if you for some reason need to reinstall Ubuntu or gets wiped your files will be safe.

And on linux do the usual “ln -s”

Step 6: Configure git
This is pretty straightforward, same as any linux environment. Generate your key and then put it on you github profile.
git config --global color.ui true
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR@EMAIL.com"
ssh-keygen -t rsa -b 4096 -C "YOUR@EMAIL.com"Step 7: bundle install, rails s
You should be ready by now; don’t forget to execute your migrations, and enjoy;

Afterword
Is it worth it ? am I ready to change completely to windows? I don’t know just yet, but for now, I have an excellent backup system that has me very happy. It is an hybrid between a tablet and a laptop with very good build quality, the OS is not that bad, the shell is native and it can have rails, that can only get better with time.
Important links:
