Ruby & Rails too

Setup

Ruby

I started to develop a new application with Ruby on Rails 6 (RoR). It has been a while since the last time I started a project with a cutting-edge RoR version, so I took the opportunity to dig a little bit about “the good, the bad and the ugly” about RoR and Ruby in general.

Looks like everybody agrees that is not dead, just not a “new toy” like it was 15 years ago, but still in pretty good shape. Some new tricks, but when I started to use it, it looks and feels quite the same, what made me happy. And, I read a lot of mentions about the new coming Ruby 3, looks like Ruby developers are promising in a near future to triplicate the speed which always has been the “but” of this language; we’ll see, we’ll see.

So I created a new Project to have a better opinion about it. I did on a Linux subsystem on Windows 10. There is a great article about how to have it installed in no time in your machine here . It’s fast, don’t add unneeded steps and it works, so why to spend time in telling you the same.

After that just open a bash console, and let’s start typing, first some common prerequisites to have Ruby and Ruby on Rails working.

# Updating everything
sudo apt-get update
# getting some needed packages 
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 postgresql-
client-common postgresql-client libpq-dev

Now let’s install Ruby with renv.

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

Now it will install the latest Ruby version, in my case 2.7.1. (It can take a little while, just be patient)

rbenv install 2.7.1
rbenv global 2.7.1
# checking ruby version
ruby -v

Let’s install Ruby’s package manager, Bundler, it will make your life so easy when installing gems and keeping track of everything installed. Believe me.

gem install bundler
rbenv rehash

Rails is dependent on NodeJS so we will need to have it installed first.

# NodeJS mapped
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
# installing NodeJS
sudo apt-get install -y nodejs
# checking
nodejs -v

Final step, install Rails:

gem install rails
rbenv rehash
# checking....
rails -v

Done! We did it!!!!

Just in case you want to have PostgreSQL although MySQL works like a charm with Ruby on Rails.

Lets download and install the latest stable version of PostgreSQL Windows binary.

PostgreSQL 9.6.2 provided by BigSQL: Download

After all the installation steps, open a bash terminal and run:

psql -p 5432 -h localhost -U postgres
# to exit the psql console, just type
\q

So these are the minimum steps to have Rails working in your Windows 10 machine under Linux system. Not so many and quite straight forward.

VirtualBox An easy way

Linux into Windows

VirtualBox

If you need to have Linux into your Windows Machine, there are some solutions but the most straight forward, to have that working in a couple of hours without deleting anything is the VirtualBox solution.

I found these two guides really good, clear and step by step:

Install Linux Inside Windows Using VirtualBox

How to install Ubuntu on VirtualBox?

Included solutions for when something could go wrong. Really useful.

Once you have follow all these steps you have a working Linux Machine, but for sure you will one to add access to some of your Windows folders. For that I found the best solution under this blog, above because it is the only link which included instructions to not just add the a shared folder, but also to make it persistent, what is a big point.

I had also some complications next day after the installation because of my second monitor, the VirtualBox was working but the Linux login was just a black screen, I could type my password and when having access Ubuntu was working without problem. I was able to solve it with this solution, just in case you have the same problem.

And if you need to add Java for your projects, just you are two steps away, open your console and type:

sudo apt update // Update your apt package index
sudo apt install default-jdk // Install the default Java Package
or
sudo apt install default-jre // If you want just the Java Runtime Environment, without Development Tools