Search code examples
rubywindowspostgresql

How to install ruby 2.4.0 in Windows 10


I have ROR projects that need different versions of ruby and one of them need ruby 2.4.0. with Postgresql. I’m using a PC with Windows 10.

How can I install more than one ruby version like in Linux with rvm? and where can I download the Ruby 2.4.0 for Windows? (I saw that rubyinstaller.org doesn’t have this version)


Solution

  • Windows 10 comes with a new feature called Windows Subsystem for Linux (WSL) that allows you to use Bash with the most common Linux tools included the ones you need to install a Ruby Manager Version.

    For this tutorial we'll set up Ubuntu on Windows, Ruby 2.4.0, Rails 5.0.1 and PostgreSQL.

    Installing Bash On Windows

    1. First enable developer mode on your machine https://www.youtube.com/watch?v=S6NvjvL3xaI

    2. Next install Windows Subsystem for Linux https://www.youtube.com/watch?v=g_5hxfFKDL8

    3. And restart your computer.

    4. After the computer reboot open a Command Prompt (CMD) and type

      > bash
      
    5. You will see the next message

      This will install Ubuntu on Windows, distributed by Canonical
      and licensed under its terms available here:
      https://aka.ms/uowterms
      Press "y" to continue: y
      
    6. Press "Y" to continue

      Downloading from the Windows Store... 100%
      Extracting filesystem, this will take a few minutes….
      
    7. Bash will ask you for a user, please remember this user because bash will ask you every time you need root permissions in Bash. Also when you time your password you won’t see the keystrokes, it’s normal, only keep typing and press ENTER when you finish.

      Please create a default UNIX user account. The username does not need to match your Windows username.
      For more information visit: https://aka.ms.wslusers
      Enter new UNIX username:
      Enter new UNIX password:
      
    8. And your Bash is ready when you see the CMD its in the mnt/c/Users/your_username directory.

      your_username@yourmachine:/mnt/c/Users/your_username$

    Installing RVM and Ruby

    1. In your bash copy this line:

      $ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
      
    2. Then install gnup2

      $ sudo apt-get install gnupg2
      

    Remember your UNIX password because every time you saw a sudo in the command you will be asked for your password.

    1. Install RVM $ \curl -sSL https://get.rvm.io -o rvm.sh

      $ cat rvm.sh | bash -s stable
      
      $ source ~/.rvm/scripts/rvm
      
    2. Install Ruby

      $ rvm install ruby-2.4.0
      

    If you need to install other version of ruby run this same command like this

    $ rvm install ruby-2.3.5

    And select the ruby version you want to use

    $ rvm --default use 2.3.5

    To check if it works

    $ ruby -v

    Installing RubyOnRails

    1. Install the Ruby’s package manager Bundler

      $ gem install bundler 
      
    2. Add NodeJS

      $ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
      
      $ sudo apt-get install -y nodejs
      
    3. Install Rails

      $ gem install rails
      

    Installing PostgreSQL

    1. Download PostgreSQL installer and follow the instructions of the installation https://www.openscg.com/bigsql/postgresql/installers.jsp/

    2. The installer will ask you for a user and a password, also keep them in a safe place because you will use it to access to PostgreSQL command line and in database.ymlin your ROR project.

    3. When the installation finish, return to bash and type the next command

      $psql -p 5432 -h localhost -U your_postgresql_username
      
    4. Bash will ask you the PostgreSQL password and if everything works you will have access to the Postgres shell prompt

      psql (9.5.6, server 9.6.2)
      WARNING: psql major version 9.5, server major version 9.6.
      Some psql features might not work.
      Type "help" for help.
      postgres=#
      
    5. Type \q to exit the Postgres shell.

    Running your Rails app

    1. Open the project in your favorite editor and update the database.yml with the PostgreSQL username and password.

      development:
        database: your_app_name_development
        username: your_postgres_user
        password: your_postgres_password
        host: localhost
        port: 5432
      
      test:
        database: your_app_name_test
        username: your_postgres_user
        password: your_postgres_password
        host: localhost
        port: 5432
      
    2. In Bash go to the directory where is your rails project, for example:

      $ cd Projects/my_app
      

    To learn more about Bash navigation visit https://www.pluralsight.com/guides/beginner-linux-navigation-manual

    1. Create your database

      $ rake db:create
      
    2. Run the rails server to make sure everything is working

      $ rails s
      
    3. And go to your browser and visit

      $ localhost:3000
      

    Every time you need a Bash, open a Command Prompt and type

    >bash -l

    For more detail of each of the commands in this tutorial, visit https://www.digitalocean.com/community/tutorials/how-to-install-ruby-and-set-up-a-local-programming-environment-on-windows-10

    https://medium.com/@colinrubbert/installing-ruby-on-rails-in-windows-10-w-bash-postgresql-e48e55954fbf