Search code examples
ruby-on-railsrubybundler

How do I use the correct version of Ruby?


I've already run bundle.

C:\Users\Chloe\workspace>rails -v
Your Ruby version is 2.3.1, but your Gemfile specified ~> 2.4.0

C:\Users\Chloe\workspace>ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x64-mingw32]

C:\Users\Chloe\workspace>path
PATH=C:\ruby24\bin;...

Solution

  • I still had C:\ruby23 in my path. I removed it, closed & reopened the shell, and now rails was not found. rails must have been using 2.3. I ran bundle again and noticed

    MSYS2 could not be found. Please run 'ridk install'
    or download and install MSYS2 manually from https://msys2.github.io/
    

    A few times. I ran the installer ridk install (even though I already had DevKit installed). I ran bundle again. But that caused an error

    Gem::InstallError: nokogiri requires Ruby version < 2.4, >= 2.1.0.
    An error occurred while installing nokogiri (1.7.0.1), and Bundler cannot
    continue.
    Make sure that `gem install nokogiri -v '1.7.0.1'` succeeds before bundling.
    

    I ran gem install rails -v 5.0.2 (same version as my Gemfile) and it installed fine, using Nokogiri 1.8.1

    Fetching: nokogiri-1.8.1-x64-mingw32.gem (100%)
    Nokogiri is built with the packaged libraries: libxml2-2.9.5, libxslt-1.1.30, zlib-1.2.11, libiconv-1.15.
    Successfully installed nokogiri-1.8.1-x64-mingw32
    

    However bundle still fails and still tries to install Nokogiri 1.7.0.1, and rails -v still fails with an error saying it cannot find Nokogiri 1.7.0.1.

    Now this is a new question so I'll create a new post.