Windows

Programming on Windows

During the last four years, until the early part of 2018, I worked on a MacBook. Sometime in the second quarter of last year, I shifted to a Windows 10 laptop. The transition has been quite smooth and delightful.

There were two Rails applications that I had to write and maintain. The first application, let’s call it webapp-1, was coded by me in 2016 using Ruby 2.3.1 p112 and Rails 4.2.6. The second application, hereafter referred to as webapp-2, is a new application that I had to write from scratch, so I chose the latest versions: Ruby 2.5.3, Rails 5.2.1.

For both these applications, the database was MySQL, and I decided to install the latest version, i.e., 8 running on Windows. The MySQL installer tools make the installation and configuration very easy and I could bring up MySQL quickly.

I started setting up the Rails environment for webapp-2 first. The installation program for windows that I downloaded was rubyinstaller-devkit-2.5.3-1-x64.exe. I ran it, selected MSYS2 and MINGW development toolchain option and the installation went through smoothly. I installed rails gem with the following command

> gem install rails –version 5.2.1

But then, when I started the rails server, I ran into a library issue. In the browser, I accessed localhost:3000 and I got a nasty looking error:

Authentication plugin ‘caching_sha2_password’ cannot be loaded: The specified module could not be found.

I had installed MySQL with SHA-256 password encryption option. The mysql2 gem on Windows does not have the required plugin. This problem could be resolved by switching to mysql_native_password. For this, I needed to do two steps: a) change the value of default_authentication_plugin to mysql_native_password in the file my.ini. b) In MySQL Workbench, run the command – ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘my_password’;

But then I thought what’s the point of using the latest version of MySQL but not its latest security feature? I raised an issue1 on github. But then, I realized that the gem wouldn’t be updated soon and also came to understand that the mysql2 gem on Linux did not have this issue. So, what to do?

It was time for Ubuntu on Windows.

I found an article2 explaining how to installing Rails on Ubuntu on Windows. Though this article instructs to start with Developer mode in Windows settings, I didn’t have to do that. Ubuntu is now an app on the Microsoft store and you just have to install that app.

In the past, I’d used rvm (on my Ubuntu Linux personal laptop) to manage my Rails versions. Therefore, I tried installing rvm first. However, I ran into a couple of errors and I switched to installing rbenv which is recommended by the article. Thereafter, the process went without a hitch.

The summary of my current programming environment is: I start MySQL on Windows. My code is in a folder called “Code” in the D drive and I edit the source code as Windows files in my IDE. In the Ubuntu console, my folder is accessible as /mnt/d/Code. I go to my project folder and run
rails server to start my application.

Well, I have captured the series of commands and some notes of the whole installation process, in the following gist:

Ran the above two commands repeatedly
$ sudo apt update
$ sudo apt install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev

Install rbenv
$ 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.3.1
$ rbenv global 2.3.1
$ ruby -v

$ gem install bundler
$ cd /mnt/d/Code

$ sudo apt install mysql-client libmysqlclient-dev

file my.cnf
[client]
protocol=TCP

file /config/database.yml
development:
    database : my_development_database
    host : 127.0.0.1

Error: Could not find proper version of railties (4.2.6) in any of the sources
$ bundle install
This installs missing gems

Start MySQl on Windows
Create database my_development_database
$ bin/rake db:migrate RAILS_ENV=development

nodejs is required.
$ curl -sL https://deb.nodesource.com/seetup_8.x | sudo -E bash -
$ sudo apt install -y nodejs
$ gem install rails -v 4.2.10
$ rbenv rehash
$ rails -v

When you create a new Rails app, you might run into the following error: parent directory is world writable but not sticky.
If you run into this issue, you can run
$ chmod +t -R ~/.bundle
and that should fix the permissions errors and let you finish the bundle install for your Rails app


Windows has some pretty good package managers. I use Chocolatey. In fact, it was one of the first programs I’d installed after I got my laptop. After installing it, it was pretty much choco install this and choco install that to get most of the tools I need.

My most frequently used tool set on Windows consists of: Outlook, Chrome, Trello, Evernote, Notepad++, Eclipse (for Java programming), VS Code (for all other programming languages), Write!, FileZilla, Cmder and Ubuntu. Apart from these, I love the Win key-D combination to go straight to the Desktop, Fn-F11 is really not quite the same thing. Anything I need is available with just the Win key, there is no need for the extra tap on the space bar.

I am loving programming on Windows and wish to have a productive year ahead. Yeah I know it’s a bit late, but might as well better late than never: here’s wishing you all a prosperous and productive 2019. Happy New Year !

References:

  1. https://github.com/brianmario/mysql2/issues/1015
  2. https://gorails.com/setup/windows/10

Published on System Code Geeks with permission by Mahboob Hussain, partner at our SCG program. See the original article here: Programming on Windows

Opinions expressed by System Code Geeks contributors are their own.

Mahboob Hussain

Mahboob is a passionate programmer for whom software construction is as beautiful a task as building the Taj Mahal. FORTRAN was the first programming language he coded in and he continues to learn new languages and frameworks and play with them. His web home is http://bit.ly/mahboob
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button