- * A Windows-based local machine (a virtual or physical one), where you can install Ruby via RubyInstaller
- * You have admin access to that machine
- * You know the differences between RVM, Rbenv, and RubyInstaller, so you know about what we're talking about here
Note: if you have Windows as your primary physical machine and want to install Ruby there, you don't need to install a virtual machine, so you can skip the first 2 steps of this blog post.
Step #1- Access to Amazon Lightsail Windows Instance
In our case, we've created a virtual Windows Machine using Amazon Lightsail, so we have to access the Lightsail console over here:
https://aws.amazon.com/lightsail/. Then, you'll be redirected to a screen similar to this one.
Step #2- Access to Windows via RDP
Remote Desktop Protocol (RDP) is a proprietary protocol developed by Microsoft which provides a user with a graphical interface to connect to another computer over a network connection. The user employs RDP client software for this purpose, while the other computer must run RDP server software.
Microsoft currently refers to their official RDP client software as Remote Desktop Connection, formerly "Terminal Services Client."
Inside Amazon Lightsail, you can see a button that you can use to launch an RDP Client without any other installation requirements, so let's click on the button called "Connect using RDP."
Then you'll be prompted with a window like this one:
This means that you're now on a Windows Machine.
Step #3- Installing Ruby via RubyInstaller for Windows
RubyInstaller combines the possibilities of native Windows programs with the rich UNIX toolset of MSYS2 and the large repository of MINGW libraries.
As a result, RubyInstaller is a great way to use Ruby for development and production, especially if you just want to use it for day-to-day scripting.
Or if you require access to Windows resources (such as hardware devices, DLLs, OLE, graphical user interfaces, or the GPU).
Note: we have to do this inside the Windows instance in Amazon Lightsail, and you'll be asked multiple times about security in Windows. Just disallow such alerts.
The first thing you can see here is that there are a lot of different versions and links to download, so at the very beginning, it could be confusing to know which one is the right to download. Let's first clarify the different sections of this download page. We have these sections
- * Ruby+Devkit Installers
- * RubyInstallers
- * Archives
- * Documentation
- * Devkits
Here is where we have to understand better why we need RubyInstaller for Windows.
Ruby gems can roughly be divided into two types. Gems that during installation do not require external tools and those that need them. The first gems are either wholly written in Ruby or have pre-built binaries for their installed system. The second type of gems is written in C/C++ and require build tools capable of compiling C/C++ source and creating shared libraries.
Whether you use Linux, OS X, or Windows operating system, you must have built tools to install such gems.
One of the goals of the RubyInstaller project was to make it possible to install gems written in C/C++ on Windows. The solution was named DevKit. A set of MSYS and MinGW-based build tools make it straightforward to build native C/C++ Ruby extensions. For Ruby 2.2, DevKit is based on the 32 bit MinGW 4.7.2 compiler suite for Windows.
According to this, we have to look for Ruby+Devkit Installers with the version we want to install. If we use RubyInstallers, we will probably find problems installing other gems and packages. So inside the Windows machine, we're going to choose the link to
- * Ruby+Devkit 2.6.8-1(x64)
Now just follow the normal installation process for Windows systems.
Once downloaded, click on the Run button.
Accept the license
Click install button
Click Next button
Wait for the installation
As you can see in this very last window, there is a box checked with the option: "Run 'ridk install' to set up MSYS2 and development toolchain. MSYS2 is required to install gems with C extensions" So, let it checked, click the Finish button, and a new terminal will be launched with the following options
Just type 1 and hit enter; you'll probably see some errors given by permissions, just let it go ahead, and finally, you'll be prompted with a successful installation.
Now you can close this window securely because it asks the same questions again, and we have already installed Ruby on our machine.
Step #4- Check the Installation
We have to go to the Windows Command Line typing CDM in the search bar inside the Amazon Lightsail instance.
Once we're there, we can type
$ ruby -v
And then we can see the version we've just installed.
Same thing if we type the command irb with 1+1 and the famous puts "Hello World."
Step #5- Having Multiple Ruby Versions in Windows
Here is where we can find some difficulties when we want to use different versions of Ruby because we have Ruby globally installed with just one version, 2.6.8, so if we have another project with a different version, we have to do the installation process again, downloading the Ruby+Devkit with the new version we want, and we can encounter versions problems between them… let make the test and see if everything works right
So let's install the latest and stable version of Ruby:
* Ruby+Devkit 3.0.3-1(x64)
Click on Run again and repeat the whole installation process.
Type 1 again, just in case
Now let's close this terminal and open it again with the CMD, as we learned previously. But wait, what will happen if we type ruby -v?
We can see now that Windows just takes one global version, the latest version installed, so how can we create different projects with different Ruby versions in Windows? This should be another blog post because it is not an easy task, so we're leaving this one here for now.
I hope you enjoyed this lecture
Thanks for reading!
Daniel Morales