Once upon a time, installing Ruby on Windows came with a myriad of problems (at least my search history can attest to that), but things have come a long way.
It's not as bad anymore...
Today, there’s no reason someone couldn’t write Ruby code on Windows. Different toolchains or not. Since most of the web is Linux based, it is a very good practice to pitch the development environment to be as close as possible to the production environment. Fortunately for us, Microsoft gave us the gift of WSL (Windows Subsystem for Linux).
This article will show the two ways you can install Ruby and Rails on Windows.
RubyInstaller is a great executable for windows that will get you up and running with Ruby on Windows. Just head over to their website and download the version with devkit.
It works its magic by using the MSYS2 system for providing Unix-like libraries on Windows as well as MinGW (Minimal Gnu for Windows), which is a large library of Unix-like packages that work on Windows. Proceed to press Enter to install the devkit.
After enabling Ubuntu (WSL). (Need help? Click here). You can open Bash and then, for starters - update out bash to the latest version
sudo apt update && sudo apt dist-upgrade && sudo apt autoremove && sudo apt clean
After that - you can proceed to install ruby with
sudo apt-get update && sudo apt-get install ruby-full
sudo apt install build-essential patch ruby-dev zlib1g-dev liblzma-dev libsqlite3-dev nodejs
After the ruby install you can proceed to install the rails gem
gem install rails
With that, you will be done! And you will then proceed to set up your environment with WSL. WSL (by default) does not have an actual directory that you can easily reach out to- for that we have to change the default directory for the bash shell so that its easier to navigate to in windows. I propose the C Drive! I'm naming my code folder to Github. ;)
cd ~
edit .bashrc
That will open the .bashrc file. Scroll down and change
cd ~
to cd /mnt/c/<your-dir-name>
After this, you can proceed to install postgresql open the bash and type the following
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O -
http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.5 libpq-dev
service postgresql start
After postgresql starts, we can now proceed to create our user
sudo -u postgres createuser yourusernamehere -s
sudo -u postgres psql
## When psql runs, type '\password yourusernamehere' then enter password when prompted.
postgres=# \password yourusernamehere
## Ctl+z to exit psql.
yourusernamehere - will be your desired postgresql username eg - johnnydoe
With that your installation will be ready and you will be able to create your rails apps and have fun!