Sunday, 10 February 2019

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:

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

5 comments:

  1. Thanks for sharing the good information and post more information. I need some facilitate to my website. please check once http://talentflames.com/
    training and placement company in Hyderabad

    ReplyDelete
  2. Please let me know if you’re looking for an author for your site. You have some great posts, and I think I would be a good asset. If you ever want to take some of the load off, I’d like to write some material for your blog in exchange for a link back to mine. Please shoot me an email if interested. Thanks.
    100% genuine mobile parts | Laptop service centre in chennai | Mobile service center in chennai | Mobile phone glass replacement | Mobile phone Battery replacement | Mobile phone Water damage service | | Laptop service centre in chennai | 100% genuine mobile parts | Laptop service centre in chennai

    ReplyDelete
  3. Thanks for sharing this blog. This is so informative blog
    Learned a lot of new things from your post!
    https://www.bharattaxi.com/

    ReplyDelete
  4. Information provided by you is very helpful and informative. Keep On updating such information.

    prestige elysian


    ReplyDelete