Ruby Woes with .rvmrc and 1.9.3 on Mac
A .rvmrc file is used by Ruby Version Manager to automatically switch to a Ruby version upon entering a project directory. The idea is that you'd have a .rvmrc file in each project directory to ensure that you always use the right Ruby version.
So, I created one of these for a new Rails project that required version 1.9.3 of Ruby and the Mac system version was just 1.8.7. Being new to Ruby I tried installing just version 1.9, figuring I'd get the latest 1.9 version:
iMac27:~ bwright$ rvm install ruby-1.9
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.8/x86_64/ruby-1.9.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Fetching yaml-0.1.4.tar.gz to /Users/bwright/.rvm/archives
Extracting yaml to /Users/bwright/.rvm/src/yaml-0.1.4
Configuring yaml in /Users/bwright/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/bwright/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/bwright/.rvm/usr
The provided compiler '/usr/bin/gcc' is LLVM based, it is not yet fully supported by ruby and gems, please read `rvm requirements`.
Reading the requirements wasn't illuminating and the compiler didn't seem to be really the problem because when I tried installing version 1.9.3, the process got much further, downloading a ton of code and then trying to compile it:
iMac27:RubymineProjects bwright$ rvm install 1.9.3
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.8/x86_64/ruby-1.9.3-p392.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Fetching yaml-0.1.4.tar.gz to /Users/bwright/.rvm/archives
Extracting yaml to /Users/bwright/.rvm/src/yaml-0.1.4
Configuring yaml in /Users/bwright/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/bwright/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/bwright/.rvm/usrInstalling Ruby from source to: /Users/bwright/.rvm/rubies/ruby-1.9.3-p392, this may take a while depending on your cpu(s)...
ruby-1.9.3-p392 - #downloading ruby-1.9.3-p392, this may take a while depending on your connection...
######################################################################## 100.0%
ruby-1.9.3-p392 - #extracting ruby-1.9.3-p392 to /Users/bwright/.rvm/src/ruby-1.9.3-p392
ruby-1.9.3-p392 - #extracted to /Users/bwright/.rvm/src/ruby-1.9.3-p392
ruby-1.9.3-p392 - #configuring
ruby-1.9.3-p392 - #compiling
Error running 'make', please read /Users/bwright/.rvm/log/ruby-1.9.3-p392/make.log
There has been an error while running make. Halting the installation.
When I looked in the log file, I found this error:
st.c:520:35: error: implicit conversion loses integer precision: 'st_index_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
i = table->num_entries++;
~ ~~~~~~~~~~~~~~~~~~^~
1 error generated.
make: *** [st.o] Error 1
This looks like a C coding error possibly brought on by the use of a 64-bit compiler on code that was meant for a 32-bit compiler. Inspecting the source code, located in ~/.rvm/source/st.c, the offending line is:
i = table->num_entries++;
located in a function with this signature:
st_add_direct(st_table *table, st_data_t key, st_data_t value)
I searched for the definition of st_table and couldn't find where that was defined in any of the source files. But fixing the code probably wasn't going to be the right approach for me. A google search found that Apple makes clang the default c compiler but that Ruby requires the gcc compiler. The solution was to just set the CC variable like this:
The first solution had it setting this variable to gcc-4.2 but that yielded a "not in path error". Looking in that directory (/usr/bin) I saw that there was a symbolic link from gcc to gcc-4.2 and switched the setting to that. I tried installing 1.9.3 again and didn't get any errors, but it finished with this ominous warning:
Install of ruby-1.9.3-p392 - #complete
Ruby 'ruby-1.9.3-p392' was built using clang - but it's not (fully) supported, expect errors.
If it was really built with clang, then what did setting CC to gcc do? It had to do something since it didn't even compile until I did that. This smells a bit...like crap.
Thinking that just setting CC wasn't enough, as there could be scripts calling other scripts, I tried, after removing 1.9.3:
and then installed again. It still used the clang compiler, printing out a warning to this effect early. I'm hoping this is just an invalid message or that I won't experience errors. We'll see.
Anyway, before I installed version 1.9.3 I noticed that I already had version 2.0.0, which was installed when I installed rvm:
iMac27:~ bwright$ rvm list
rvm rubies
jruby-1.7.3 [ x86_64 ]
* ruby-2.0.0-p0 [ x86_64 ]
Why wouldn't 2.0.0 work? I put that in the .rvmrc file:
rvm ruby-2.0.0-p0@GoalTracker
And when I cd-ed to that directory I got this, expected, message:
Gemset 'GoalTracker' does not exist, 'rvm gemset create GoalTracker' first, or append '--create'.
But when I ran that command I saw this:
iMac27:GoalTracker bwright$ rvm list
rvm rubies
jruby-1.7.3 [ x86_64 ]
=* ruby-2.0.0-p0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
iMac27:GoalTracker bwright$ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]
iMac27:GoalTracker bwright$ cd ..
iMac27:RubymineProjects bwright$ cd GoalTracker/
Gemset 'GoalTracker' does not exist, 'rvm gemset create GoalTracker' first, or append '--create'.
iMac27:GoalTracker bwright$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
iMac27:GoalTracker bwright$ rvm gemset create GoalTracker
gemset created GoalTracker => /Users/bwright/.rvm/gems/jruby-1.7.3@GoalTracker
I was using Ruby 2.0 when I entered the directory and by entering it, I got switched to the system version (1.8.7) and when I tried to create the gemset for the project, it was put under jruby?! How can that behavior be explained?
I fixed this by making sure I was using the right version before trying to add the gem.
What a pain. Is this just Apple/Macs not playing nice? Or Ruby crap? I'll assume the former.
So, I created one of these for a new Rails project that required version 1.9.3 of Ruby and the Mac system version was just 1.8.7. Being new to Ruby I tried installing just version 1.9, figuring I'd get the latest 1.9 version:
iMac27:~ bwright$ rvm install ruby-1.9
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.8/x86_64/ruby-1.9.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Fetching yaml-0.1.4.tar.gz to /Users/bwright/.rvm/archives
Extracting yaml to /Users/bwright/.rvm/src/yaml-0.1.4
Configuring yaml in /Users/bwright/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/bwright/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/bwright/.rvm/usr
The provided compiler '/usr/bin/gcc' is LLVM based, it is not yet fully supported by ruby and gems, please read `rvm requirements`.
Reading the requirements wasn't illuminating and the compiler didn't seem to be really the problem because when I tried installing version 1.9.3, the process got much further, downloading a ton of code and then trying to compile it:
iMac27:RubymineProjects bwright$ rvm install 1.9.3
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.8/x86_64/ruby-1.9.3-p392.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Fetching yaml-0.1.4.tar.gz to /Users/bwright/.rvm/archives
Extracting yaml to /Users/bwright/.rvm/src/yaml-0.1.4
Configuring yaml in /Users/bwright/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/bwright/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/bwright/.rvm/usrInstalling Ruby from source to: /Users/bwright/.rvm/rubies/ruby-1.9.3-p392, this may take a while depending on your cpu(s)...
ruby-1.9.3-p392 - #downloading ruby-1.9.3-p392, this may take a while depending on your connection...
######################################################################## 100.0%
ruby-1.9.3-p392 - #extracting ruby-1.9.3-p392 to /Users/bwright/.rvm/src/ruby-1.9.3-p392
ruby-1.9.3-p392 - #extracted to /Users/bwright/.rvm/src/ruby-1.9.3-p392
ruby-1.9.3-p392 - #configuring
ruby-1.9.3-p392 - #compiling
Error running 'make', please read /Users/bwright/.rvm/log/ruby-1.9.3-p392/make.log
There has been an error while running make. Halting the installation.
When I looked in the log file, I found this error:
st.c:520:35: error: implicit conversion loses integer precision: 'st_index_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
i = table->num_entries++;
~ ~~~~~~~~~~~~~~~~~~^~
1 error generated.
make: *** [st.o] Error 1
This looks like a C coding error possibly brought on by the use of a 64-bit compiler on code that was meant for a 32-bit compiler. Inspecting the source code, located in ~/.rvm/source/st.c, the offending line is:
i = table->num_entries++;
located in a function with this signature:
st_add_direct(st_table *table, st_data_t key, st_data_t value)
I searched for the definition of st_table and couldn't find where that was defined in any of the source files. But fixing the code probably wasn't going to be the right approach for me. A google search found that Apple makes clang the default c compiler but that Ruby requires the gcc compiler. The solution was to just set the CC variable like this:
iMac27:RubymineProjects bwright$ CC=/usr/bin/gcc
The first solution had it setting this variable to gcc-4.2 but that yielded a "not in path error". Looking in that directory (/usr/bin) I saw that there was a symbolic link from gcc to gcc-4.2 and switched the setting to that. I tried installing 1.9.3 again and didn't get any errors, but it finished with this ominous warning:
Install of ruby-1.9.3-p392 - #complete
Ruby 'ruby-1.9.3-p392' was built using clang - but it's not (fully) supported, expect errors.
If it was really built with clang, then what did setting CC to gcc do? It had to do something since it didn't even compile until I did that. This smells a bit...like crap.
Thinking that just setting CC wasn't enough, as there could be scripts calling other scripts, I tried, after removing 1.9.3:
export CC=/usr/bin/gcc
and then installed again. It still used the clang compiler, printing out a warning to this effect early. I'm hoping this is just an invalid message or that I won't experience errors. We'll see.
Anyway, before I installed version 1.9.3 I noticed that I already had version 2.0.0, which was installed when I installed rvm:
iMac27:~ bwright$ rvm list
rvm rubies
jruby-1.7.3 [ x86_64 ]
* ruby-2.0.0-p0 [ x86_64 ]
Why wouldn't 2.0.0 work? I put that in the .rvmrc file:
rvm ruby-2.0.0-p0@GoalTracker
And when I cd-ed to that directory I got this, expected, message:
Gemset 'GoalTracker' does not exist, 'rvm gemset create GoalTracker' first, or append '--create'.
But when I ran that command I saw this:
iMac27:GoalTracker bwright$ rvm list
rvm rubies
jruby-1.7.3 [ x86_64 ]
=* ruby-2.0.0-p0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
iMac27:GoalTracker bwright$ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]
iMac27:GoalTracker bwright$ cd ..
iMac27:RubymineProjects bwright$ cd GoalTracker/
Gemset 'GoalTracker' does not exist, 'rvm gemset create GoalTracker' first, or append '--create'.
iMac27:GoalTracker bwright$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
iMac27:GoalTracker bwright$ rvm gemset create GoalTracker
gemset created GoalTracker => /Users/bwright/.rvm/gems/jruby-1.7.3@GoalTracker
I was using Ruby 2.0 when I entered the directory and by entering it, I got switched to the system version (1.8.7) and when I tried to create the gemset for the project, it was put under jruby?! How can that behavior be explained?
I fixed this by making sure I was using the right version before trying to add the gem.
What a pain. Is this just Apple/Macs not playing nice? Or Ruby crap? I'll assume the former.
