The Daily Parker

Politics, Weather, Photography, and the Dog

Getting a Rails app to run on Bash on Ubuntu on Windows

(This is a cross-post with my employer's blog.)

I'm the newest team member at DevMynd, and so far, the only one with a Windows PC. Since we do most of our work in Ruby on Rails, and since everyone else has Macs, this presents a challenge.

If I wanted to do this the easy way, I'd simply run Rails on Windows natively. But I decided instead to do it the hard way and use Linux and BASH. First, I had a couple of free days to get up to speed last week giving me some time to experiment. Second, I figured that running on a completely different platform might introduce hard-to-diagnose bugs. (Both Linux and MacOS are *nix operating systems while Windows is not). I hope that what follows will make this a considerably less-hard way for everyone else.

This is how I got everything working on a Windows 10 Creator Edition (build 10.0.15603) box using Bash on Ubuntu on Windows also known as Bash/WSL. WSL (Windows Subsystem for Linux) is a beta feature of Windows 10 so some of what follows may be different on other versions of Windows.

Also, this post assumes that you are coming into the Linux world for the very first time, and your mind is a deep, pure, clear lake of Windows expertise completely unencumbered by any knowledge of Linux whatsoever. If you already know Linux, a lot of this might be redundant.

Important!

  • Don’t change Linux files using Windows apps and tools. You will hose your Linux environment. That said, since your Bash/WSL environment can read the Windows file system, you can just point to it from within BASH to run your Rails project.
  • Read the Bash on Ubuntu on Windows FAQ.

Steps

1.  Turn on Developer Mode

In Developer Features, turn on "Developer mode". You will need to reboot after this step.

2. Turn on WSL

In Windows Features, turn on "Windows Subsystem for Linux (beta)". You will need to reboot after this step.

3. Run BASH as administrator.

(Window key, "Bash", right click, "run as administrator.")

4. Install Ubuntu

(Ubuntu is the only *nix image available for WSL at the moment, following a partnership between Microsoft and Canonical.)

When BASH starts, it will prompt you to install Ubuntu on Windows. Hit "y" to do so.

5. Install Ruby prerequisites

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-dev

6. Install rbenv

rbenv will let you use different versions of both Ruby and Rails as needed:

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

7. Install Ruby

Install the version or versions of Ruby you'll need to use. For example, to install v2.4.0:

rbenv install 2.4.0

(Optional) Set a global, default version of Ruby. For example, to make v.2.4.0 the default on your system:

rbenv global 2.4.0

(Optional) Check what version of Ruby you're using as a default:

ruby -v
rbenv -versions

8. Install Bundler:

gem install bundler

Then Rehash rbenv:

rbenv rehash

9. Install Rails

5.0.1 shown; you can install multiple versions

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

gem install rails -v 5.0.1

10. (Optional) Install MySQL

MySQL

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Test your installation

Now you're ready to create a sample application and see if it works.

1. Create an empty Rails application with a database.

a. SQLite

Create an empty application using the Rails default SQLite database:

rails new deleteme

b. MySQL

Create an empty application using MySQL and then start the MySQL server:

rails new deleteme -d mysql
sudo /etc/init.d/mysql start

2. Initialize your application.

This is the happy path:

cd deleteme
rake db:create
rails server

3. View your application

Open a browser and navigate to http://localhost:3000.

Congratulations!

You should now be looking at a Ruby on Rails welcome screen. Happy BASHing.

In a subsequent post, I'll look at installing Postgres on Bash/WSL, and all the things I had to fix while doing it.

A year of Google Maps

Via my company's Slack #general channel, San Francisco cartographer Justin O'Beirne has analyzed the changes Google has made to its Maps feature over the past year, while Apple Maps has stagnated:

So it seems that Apple is updating its map more frequently than Google.

But when we look closer, this doesn’t seem to be what’s happening. For instance, near the park’s southeast corner, there’s a group of three auto service-related businesses: Domport Auto Body ServiceFell Street Auto Service, and California Detailing...

Google has distinct locations for each. But Apple plots them at the same location...

...and as the months pass by, Apple cycles through all three – padding our addition/removal counts...

A number of the additions and removals we counted earlier on Apple are similar – the map is cycling though businesses plotted at the same location.

This all seems to suggest that Google’s location data is more precise than Apple’s. (Or that Apple’s geocoder is buggy.) And perhaps here we’re seeing the fruits of Google’s decade-long Street View project...

It's a long essay with tons of examples and animations. Total Daily Parker bait.

Speaking of my company, I'll have a post up on the company's blog shortly which I'll cross-post here. Keep your eyes peeled.

This IS the golden age of air travel

Pilot and author Patrick Smith points out that air travel is so much better than it was even 20 years ago, it's hard to see how far we've come:

People often talk about a proverbial “golden age” of air travel, and if only we could return to it. That’s an easy sentiment to sympathize with. I’m old enough to recall when people actually looked forward to flying. I remember a trip to Florida in 1979, and my father putting on a coat and tie for the occasion. I remember cheesecake desserts on a 60-minute flight in economy. Yes, things were once a little more comfortable, a little more special.

One of the reasons that flying has become such a melee is because so many people now have the means to partake in it. It wasn’t always this way. Adjusted for inflation, the average cost of a ticket has declined about 50 percent over the past 35 years. This isn’t true in every market, but on the whole fares are far cheaper than they were 30 years ago. (And yes, this is after factoring in all of those add-on “unbundling” fees that airlines love and passengers so despise.)

I could mention, too, that the airplanes of decades past were louder — few things were more deafening than a 707 at takeoff thrust — and more gas-guzzling and polluting. And if, in 2017, you’re put off by a lack of legroom or having to pay for a sandwich, how would you feel about sitting for eight hours in a cabin filled with tobacco smoke? As recently as the 1990s, smoking was still permitted on airplanes.

As for legroom, there’s that conventional wisdom again, contending that airlines are forever cramming more rows into their aircraft. Except it’s not necessarily true. The spacing between rows, called “pitch” in the business, is, on average, less than it was 20 or 30 years ago — and yes, passengers themselves have become larger on average — but only slightly. Remember Laker Airways, whose “Skytrain” service ran between the United States and London in the 1970s and early ’80s? Sir Freddie Laker, the airline’s flamboyant founder, configured his DC-10s with a bone-crunching 345 seats — about a hundred more than the typical DC-10 at the time.

Sure, air travel is a pain in the ass. But it's safer, cheaper, more accessible, more convenient, quieter, and faster than it's ever been.

Europe's worst case scenario

We have a child in the White House. And European leaders are saying they can no longer rely on the United States:

Trump’s speech alone is likely a sufficient explanation. But I suspect there’s an additional element. Most of the major European and NATO leaders had already met Trump in Washington – Merkel, May, Gentiloni, Trudeau and others. But I suspect in meeting as a group, over a more extended period and in a context specifically focused on Europe and NATO there was a further realization that what they are watching from across the Atlantic is no act. Indeed, Trump appears more impulsive and erratic in person than on TV. Rather than growing into the job he’s growing into the role of aggressor.

Another, perhaps more critical realization, is suggested in this Twitter thread by Max Fisher of the Times: That is, it’s not just that Trump is greedy or impulsive or unreliable, indifferent to the North Atlantic alliance but that he is positively against it. He and Vladimir Putin are in a de facto alliance against ‘Europe’ or to put it less geographically, the liberal internationalist state system which has rested on and built out from the United States and Western Europe.

I've imagined the damage that Trump can do to the world, and I am seeing how what I've imagined is coming to pass. I hope Europe is stronger than they have seemed so far.

The Pope and the pagan

Andrew Sullivan's note Friday analyzes the President's trip to the Vatican from a distinctly conservative and Catholic perspective:

Trump is not an atheist, confident yet humble in the search for a God-free morality. He is not an agnostic, genuinely doubtful as to the meaning of existence but always open to revelation should it arrive. He is not even a wayward Christian, as he sometimes claims to be, beset by doubt and failing to live up to ideals he nonetheless holds. The ideals he holds are, in fact, the antithesis of Christianity — and his life proves it. He is neither religious nor irreligious. He is pre-religious. He is a pagan. He makes much more sense as a character in Game of Thrones, a medieval world bereft of the legacy of Jesus of Nazareth, than as a president of a modern, Western country.

Every pillar of Trump’s essential character is a cardinal sin for Christians: lust, gluttony, greed, envy, anger, and pride. We are all guilty of these, of course, but there is in Trump a centrality to them, a shame-free celebration of them, that is close to unique in the history of the American presidency. I will never understand how more than half of white Catholics could vote for such a man, or how the leadership of the church could be so terribly silent when such a monster stalks the earth.

He also fumes about Trump's trip to Saudi Arabia, a country we trade with but shouldn't exactly want to emulate.

Walking through the neighborhoods

I took a short walk today, from Central Street in Evanston to my house. Totals: 16.37 km, 2:25:29, 8'53" per km, 18,357 steps. It's not as far as my epic 28 km walk last June, but I'll probably do another walk that distance sometime later this year. I mean, why not a 32 km walk?

Right. Because my feet hurt.

So far today I'm just shy of 30,000 steps. So I'm not quite in the top 5—but I will be if I walk another thousand steps, which seems pretty likely:

2016 Jun 16 40,748
2016 Oct 23 36,105
2016 Sep 25 32,354
2016 Jun 8 32,315
2015 Apr 26 30,496
2016 Mar 8 29,775
So far today 29,445

And here's the meandering route I took:

Don't push that button!

British Airways cancelled all of its flights out of its two biggest hubs in London today because of a power-supply failure:

The airline hoped to be able to operate some long haul inbound flights on Saturday, landing in London on Sunday, Mr Cruz added.

The GMB union has suggested the failure could have been avoided, had the airline not outsourced its IT work.

BA refuted the claim, saying: "We would never compromise the integrity and security of our IT systems".

All passengers affected by the failure - which coincides with the first weekend of the half-term holiday for many in the UK - will be offered the option of rescheduling or a refund.

The airline, which had previously said flights would be cancelled until 18:00 BST, has now cancelled all flights for Saturday and asked passengers not to come to Gatwick or Heathrow airports.

Some things never change.

Windows moves to Git

The Microsoft Windows operating system has millions of lines of code maintained by thousands of developers. And in the past three months, Microsoft has moved 90% of its code to the open-source Git version control system:

The switch to Git has been driven by a couple of things. In 2013, the company embarked on its OneCore project, unifying its different strands of Windows development and making the operating system a more cleanly modularized, layered platform. At the time, Microsoft was using SourceDepot, a customized version of the commercial Perforce version control system, for all its major projects.

SourceDepot couldn't handle a project the size of Windows, so rather than having the whole operating system in a single repository, the Windows code was actually divided among 65 different repositories, with a kind of virtualization layer on top to produce a unified view of all the code. Some of these 65 repos contained nicely isolated, standalone components; others took vertical or horizontal slices through the operating system; others were just grab bags of different code. As such, the repo structure didn't correspond with OneCore's module boundaries.

Due to widespread developer familiarity and strong support for creating lots of branches with low overhead, the decision was made to use Git as the new system. But Git isn't designed to handle 300GB repositories made up of 3.5 million files. Microsoft had to embark on a project to customize Git to enable it to handle the company's scale.

You read that right: Windows contains 3.5 million individual code files, and there are so many changes to them (8,500 per day on average), they had to create their own super-charged version of Git.

Programming nerds will want to read the whole article. Non-nerds can scroll down for political stuff.

Latter days of the Republic

"A dying culture invariably exhibits personal rudeness. Bad manners. Lack of consideration for others in minor matters. A loss of politeness, of gentle manners, is more significant than is a riot."

Robert HeinleinFriday

Montana's at-large congressional district will stay Republican after millionaire Greg Gianforte won yesterday's special election by 6 points. This is despite him assaulting a reporter Wednesday afternoon and being charged with the crime:

The Republican candidate for Montana’s congressional seat has been charged with misdemeanor assault after he is alleged to have slammed a Guardian reporter to the floor on the eve of the state’s special election, breaking his glasses and shouting: “Get the hell out of here.”

Ben Jacobs, a Guardian political reporter, was asking Greg Gianforte, a tech millionaire endorsed by Donald Trump, about the Republican healthcare plan when the candidate allegedly “body-slammed” the reporter.

“He took me to the ground,” Jacobs said by phone from the back of an ambulance. “I think he whaled on me once or twice … He got on me and I think he hit me … This is the strangest thing that has ever happened to me in reporting on politics.”

A Fox News TV team corroborated Jacobs' report.

Reactions immediately split along Republican/everyone else lines:

The Montana donnybrook quickly became a Rorschach Test that highlighted the divide within the conservative media between the serious and unserious outlets. It also showcased how many prominent figures on the right reflexively rally behind Republican politicians, whether the president or a House candidate, even when they are very clearly in the wrong. This is part of a growing tribalism that contributes to the polarization of our political system.

Laura Ingraham aggressively questioned the Fox reporter on her radio show: “You can’t body-slam someone by holding both hands on the neck. That’s impossible…Didn’t he grab him near the neck and throw him down? Just asking.” Acuna held firm: “I saw both his hands go up not around his neck in a strangling type of way, but more just on each side of his neck, just grabbed him. I guess it could have been on his clothes, I don’t know. I can’t say that for sure. But he grabbed him and slammed him down. … He had one hand on each side of his neck.”

And while the news division at Fox covered the story seriously and showed integrity, at least one commentator said on the air that the reporter had it coming.

And then there was this gem, demonstrating what happens when a media outlet becomes a monopoly in a market:

The Montana NBC Affiliate reportedly refused to cover the Gianforte story at all on Wednesday night, a shocking blackout. Irate sources inside 30 Rock appear to have called up New York Magazine’s Yashar Ali to complain: “KECI news director Julie Weindel was called by NBC News to see if KECI would cover the story or had any footage of the Gianforte incident that NBC News and its affiliates could use. … She was unyielding in her refusal to share any footage she may have had access to, or run a report on the story. … Weindel said that they weren’t covering the story, though it was running in outlets across the country at the time, explaining, ‘The person that tweeted [Jacobs] and was allegedly body slammed is a reporter for a politically biased publication.’ Weindel then added, ‘You are on your own for this.’ … The station was acquired, last month, by the conservative media conglomerate Sinclair Broadcasting.”

Here’s why that’s a big deal: Sinclair Broadcasting just struck a deal with Tribune Media to buy dozens of local TV stations. “Already, Sinclair is the largest owner of local TV stations in the nation. If the $3.9 billion deal gets regulatory approval, Sinclair would have 7 of every 10 Americans in its potential audience,” Margaret Sullivan explained in a column last weekend. “Sinclair would have 215 stations, including ones in big markets such as Los Angeles, New York City and Chicago, instead of the 173 it has now. There’s no reason to think that the FCC’s new chairman, Ajit Pai, will stand in the way. Already, his commission has reinstated a regulatory loophole — closed under his predecessor, Tom Wheeler — that allows a single corporation to own more stations than the current 39 percent nationwide cap…"

Meanwhile, the president appeared to shove the prime minister of Montenegro out of the way at a photo-op yesterday.

Who said Donald Trump would spread poison to everything he touched? Oh right. Everyone paying attention.