Rails ActiveSupport time and timezone error on Alpine Linux - ruby

I don't know if I am doing something stupid, so bear with me.
tl;dr Rails ActiveSupport time and timezone seems to have an error on Alpine Linux. It uses the DST variant (summer time) of my timezone when it should use the winter time.
Steps to reproduce:
Start a shell in a Docker Alpine Linux Ruby image:
$ docker run -it --rm ruby:2.7.1-alpine sh
All following steps happen inside the running docker container.
Install timezone data:
$ apk add --no-cache --update tzdata
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(1/1) Installing tzdata (2020c-r0)
Executing busybox-1.31.1-r9.trigger
OK: 23 MiB in 37 packages
Print standard ruby current time:
$ ruby -e 'puts Time.now.inspect'
2020-10-28 20:34:24.4817918 +0000
Looks good. Time is printed in UTC.
Besides UTC, standard ruby Time class can only handle local time. This is dependent on the local system timezone, which can be configured using operating system configuration mechanisms, or which can simply be passed to Ruby with the TZ env var. Let's try to use my timezone "Europe/Berlin":
$ TZ="Europe/Berlin" ruby -e 'puts Time.now.inspect'
2020-10-28 21:39:22.7037648 +0100
Looks good. Berlin timezone is UTC+01 in winter (standard) or UTC+02 in summer (DST). At the time of this writing, we have winter time, so +0100 is fine.
Now let's move to ActiveSupport:
$ gem install activesupport
Fetching tzinfo-1.2.7.gem
Fetching i18n-1.8.5.gem
Fetching activesupport-6.0.3.4.gem
# #### many more lines of output ####
Successfully installed activesupport-6.0.3.4
6 gems installed
In contrast to standard ruby, ActiveSupport supports all possible timezones, rather than only two. Getting the current time is Time.current, so let's try this:
$ ruby -e 'require "active_support/all"; puts Time.current.inspect'
2020-10-28 20:43:51.1098842 +0000
This looks not different from the output of step 3. The reason for this is that Time.current only behaves differently than Time.now when a timezone is configured.
We can configure a timezone for ActiveSupport with Time.zone=(timezone_identifier) or with Time.use_zone(timezone_identifier) { "inside this block the timezone is used" }. Let's try the first variant:
$ ruby -e 'require "active_support/all"; Time.zone = "UTC"; puts Time.current.inspect'
Wed, 28 Oct 2020 20:50:55 UTC +00:00
We are still on UTC, but the output looks different than before. From this we know that we got a ActiveSupport::TimeWithZone object. This is good.
Now I want the same for my timezone:
$ ruby -e 'require "active_support/all"; Time.zone = "Europe/Berlin"; puts Time.current.inspect'
Wed, 28 Oct 2020 22:52:21 CEST +02:00
On a first glance this looks good, but compare it carefully with the output of step 4. In "Europe/Berlin" timezone we currently have winter time, UTC+01, also called "CET" (central european time). But this time in the output the timestamp is labeled as being "CEST" (central european summer time), which is UTC+02.
And this is wrong.
Where is the error? Is it in Alpine Linux? Is it in standard Ruby? But the output is correct in step 4. Or is the error in ActiveSupport or its connection to the timezone data? Am I doing something wrong?

Turns out this is an issue affecting the tzinfo gem (versions < 1.2.8 / < 2.0.3) - it's incompatible with timezone-data 2020b (onwards?), and recent versions of Alpine ship with 2020c. The file format changed from 'fat' to 'slim' which isn't compatible with the tzinfo gem yet.
Updated solution (2020-11-09)
Support for "slim" format zoneinfo files has now been added to the tzinfo gem in releases:
v1.2.8
v2.0.3
Original Ruby solution
You can use the tzinfo-data gem instead of relying on the system tzinfo:
gem install activesupport tzinfo-data
ruby -e 'require "active_support/all"; Time.zone = "Europe/Berlin"; puts TZInfo::DataSource.get; puts Time.current.inspect'
# Ruby DataSource
# Thu, 29 Oct 2020 16:25:08 CET +01:00
Original Alpine solution
You can rebuild the time zone data package in the 'fat' format (adapted from comment):
FROM ruby:2.7.2-alpine
# Install tzdata because we need the zic binary
RUN apk add --no-cache tzdata
# Fix incompatibility with slim tzdata from 2020b onwards
RUN wget https://data.iana.org/time-zones/tzdb/tzdata.zi -O /usr/share/zoneinfo/tzdata.zi && \
/usr/sbin/zic -b fat /usr/share/zoneinfo/tzdata.zi
Then testing the time in Europe/Berlin:
gem install activesupport
ruby -e 'require "active_support/all"; Time.zone = "Europe/Berlin"; puts TZInfo::DataSource.get; puts Time.current.inspect'
# Zoneinfo DataSource: /usr/share/zoneinfo
# Thu, 29 Oct 2020 16:29:19 CET +01:00

Related

Ruby hangs on load using RVM

Installed ruby 2.4.0 using RVM, but after typing ruby, the command just freezes indefinitely. Can be ctrl-C'ed out, but ruby never loads.
Ruby info:
ruby-2.4.0:
system:
uname: "Linux waffleboy 4.8.0-58-generic #63~16.04.1-Ubuntu SMP Mon Jun 26 18:08:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux"
name: "Ubuntu"
version: "16.04"
architecture: "x86_64"
bash: "/bin/bash => GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)"
zsh: "/usr/bin/zsh => zsh 5.1.1 (x86_64-ubuntu-linux-gnu)"
remote path: "ubuntu/16.04/x86_64"
rvm:
version: "rvm 1.29.2 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]"
updated: "23 minutes 20 seconds ago"
path: "/home/waffleboy/.rvm"
autolibs: "[4] Allow RVM to use package manager if found, install missing dependencies, install package manager (only OS X)."
ruby:
interpreter: "ruby"
version: "2.4.0p0"
date: "2016-12-24"
platform: "x86_64-linux"
patchlevel: "2016-12-24 revision 57164"
full_version: "ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]"
homes:
gem: "/home/waffleboy/.rvm/gems/ruby-2.4.0"
ruby: "/home/waffleboy/.rvm/rubies/ruby-2.4.0"
binaries:
ruby: "/home/waffleboy/.rvm/rubies/ruby-2.4.0/bin/ruby"
irb: "/home/waffleboy/.rvm/rubies/ruby-2.4.0/bin/irb"
gem: "/home/waffleboy/.rvm/rubies/ruby-2.4.0/bin/gem"
rake: "/home/waffleboy/.rvm/rubies/ruby-2.4.0/bin/rake"
environment:
PATH: "/home/waffleboy/.rvm/gems/ruby-2.4.0/bin:/home/waffleboy/.rvm/gems/ruby-2.4.0#global/bin:/home/waffleboy/.rvm/rubies/ruby-2.4.0/bin:/storage/anaconda3/bin:/home/waffleboy/bin:/home/waffleboy/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/usr/bin:/storage/programfiles/:/home/waffleboy/bin:/storage/programfiles/spark-1.6.2/bin:/home/waffleboy/.rvm/bin"
GEM_HOME: "/home/waffleboy/.rvm/gems/ruby-2.4.0"
GEM_PATH: "/home/waffleboy/.rvm/gems/ruby-2.4.0:/home/waffleboy/.rvm/gems/ruby-2.4.0#global"
MY_RUBY_HOME: "/home/waffleboy/.rvm/rubies/ruby-2.4.0"
IRBRC: "/home/waffleboy/.rvm/rubies/ruby-2.4.0/.irbrc"
RUBYOPT: ""
gemset: ""
Rvm list:
rvm rubies
=* ruby-2.4.0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
I've tried reinstalling and installing ruby multiple times but it just doesn't seem to work.
Can anyone point me in the right direction? :) Thank you!
This is normal; it is a feature, not a bug.
Running ruby, without any parameters, causes the program to run and wait to receive input from STDIN (ending with an EOF character). It will not execute anything until it receives this information.
If you want to run ruby in interactive mode, (like when you run python), then use ruby's built-in irb ("interactive ruby") command.
Alternatively, if you just want to display some basic information about the ruby version installed then you can try commands like:
ruby -v # Display version information
ruby -h # Display help about usage, switches and features
If you're looking for a REPL to type Ruby code into, have it executed, and see the results, then you're looking for the irb command, not ruby.
ruby is for running files (eg. ruby my_file.rb), or without arguments will read a script typed into standard input, which will get executed when you quit ruby with cmd+D.

Building a ruby script with Ocra for cross platform uses but i get the 'relative_path_form' with a stacktrace

I'm trying to build a .exe to execute my script on Windows without any ruby installation.
I'm using Ocra for that but i have a stack trace.
Also note that there are two files that runs the whole sc and that I use currently RVM and I didn't do any sudo gem install since I use RVM.
Gems used in the first file :
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'colorize'
require 'colorized_string'
Gems used in the second file :
require 'libnotify'
require './firstfile'
require 'os'
require 'twilio-ruby'
Here is what Ocra gives me:
>ocra --output test.exe firstfile.rb secondfile.rb
/home/xxxx/.rvm/gems/ruby-head/gems/ocra-1.3.6/bin/ocra:41:in `relative_path_from': undefined method `path' for "/home/xxxx/.rvm/gems/ruby-head#global":String (NoMethodError)
from /home/xxxx/.rvm/gems/ruby-head/gems/ocra-1.3.6/bin/ocra:779:in `block in build_exe'
from /home/xxxx/.rvm/gems/ruby-head/gems/ocra-1.3.6/bin/ocra:762:in `each'
from /home/xxxx/.rvm/gems/ruby-head/gems/ocra-1.3.6/bin/ocra:762:in `build_exe'
from /home/xxxx/.rvm/gems/ruby-head/gems/ocra-1.3.6/bin/ocra:1177:in `block in <top (required)>'
Here is more info about my rvm and my ruby version it's the exact output of 'rvm info'
system:
uname: "Linux xxxx 4.7.1-1-ARCH #1 SMP PREEMPT Wed Aug 17 08:13:35 CEST 2016 x86_64 GNU/Linux"
system: "arch/libc-2.24/x86_64"
bash: "/usr/bin/bash => GNU bash, version 4.3.46(1)-release (x86_64-unknown-linux-gnu)"
zsh: " => not installed"
rvm:
version: "rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]"
updated: "1 day 23 hours 44 minutes 51 seconds ago"
path: "/home/xxxx/.rvm"
ruby:
interpreter: "ruby"
version: "2.4.0dev"
date: "2016-05-20"
platform: "x86_64-linux"
patchlevel: "2016-05-20 trunk 55077"
full_version: "ruby 2.4.0dev (2016-05-20 trunk 55077) [x86_64-linux]"
homes:
gem: "/home/xxxx/.rvm/gems/ruby-head"
ruby: "not set"
binaries:
ruby: "/home/xxxx/.rvm/rubies/ruby-head/bin/ruby"
irb: "/home/xxxx/.rvm/rubies/ruby-head/bin/irb"
gem: "/home/xxxx/.rvm/rubies/ruby-head/bin/gem"
rake: "/home/xxxx/.rvm/gems/ruby-head/bin/rake"
environment:
PATH: "/home/xxxx/.rvm/gems/ruby-head/bin:/home/xxxx/.rvm/gems/ruby-head#global/bin:/home/xxxx/.rvm/rubies/ruby-head/bin:/home/xxxx/.rvm/bin:/usr/bin"
GEM_HOME: "/home/xxxx/.rvm/gems/ruby-head"
GEM_PATH: "/home/xxxx/.rvm/gems/ruby-head:/home/xxxx/.rvm/gems/ruby-head#global"
MY_RUBY_HOME: ""
IRBRC: ""
RUBYOPT: ""
gemset: ""
My script parse an HTML page and also has to create a file inside the folder it is, write/read to this file and also Libnotify has to set a this i don't know how to exactly explain it but it's some kind of path :
Libnotify.icon_dirs << '/home/' + ENV['USER'] + '/Downloads/NotificationIcons/'
So maybe one of those is what Ocra means by relative path but I'm not sure a 100% that's why I'd like to understand what 'relative path' explicitly means and also why do I have this stack trace with this error.
PS: The 'xxxx' are just here for privacy !
Thanks for any help in advance I'm currently stuck in packaging my project to cross-platforms for now I'm just trying to get it on Windows.
If you need anymore information just ask for it, also be gentle if I made any mistakes as this is my first question asked on Stack Overflow.
Ocra doesn't work on Linux currently.
Doing a google search for
ocra undefined method `path'
Linked here, an issues page on the Ocra github which shows many people have had the same problem. This in turns links here, where the project maintainer says that Ocra does not work on Linux, though it may be worth a shot with Wine.

can server locale settings affect JSON parsing (Ruby)

I have an issue with a script that is parsing some data which is stored in Redis, the particular hash of data has this in a string:
\u00a3575,000. which is £575,000
Redis is storing it as a £ when i pull it out. But when I pass the string to JSON.parse it returns an error saying:
Unexpected error while processing request: "\xC2" on US-ASCII
I have been through the server and tested it on our UAT platform and it is fine, it parses fine and returns exactly what I expect, however on the live server which is the same as the UAT server (Ruby version, RVM version, Redis version) it gives the above error.
I have been through the server settings and the only thing I can see different is the locale settings (Ubuntu 12.04)
on UAT its set to en_GB.UTF-8
on live its set to en_US.UTF-8
Before I left the office I changed the locale settings, but ran out of time to reboot the server and can't now until tomorrow morning (its IP locked for ssh to the office). However like most coders I know, I can't stop thinking about the problem, hence coming to ask here if it can make a difference. If it can't can anyone point me in the right direction to come up with a solution?
ps. I did add this line:
result = result.force_encoding(Encoding::UTF_8)
which worked but feel that, as I didn't need to do this on UAT, it feels wrong to make a code change like that to bend to a problem with the environment.
many thanks
ops: if this helps answer why i am getting the error, then: my output from rvm info
ruby-2.1.1:
system:
uname: "Linux ip-10-82-168-126 3.2.0-54-virtual #82-Ubuntu SMP Tue Sep 10 20:31:18 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux"
system: "ubuntu/12.04/x86_64"
bash: "/bin/bash => GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)"
zsh: " => not installed"
rvm:
version: "rvm 1.25.27 (stable) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]"
updated: "3 hours 15 minutes 33 seconds ago"
path: "/usr/local/rvm"
ruby:
interpreter: "ruby"
version: "2.1.1p76"
date: "2014-02-24"
platform: "x86_64-linux"
patchlevel: "2014-02-24 revision 45161"
full_version: "ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]"
homes:
gem: "/usr/local/rvm/gems/ruby-2.1.1"
ruby: "/usr/local/rvm/rubies/ruby-2.1.1"
binaries:
ruby: "/usr/local/rvm/rubies/ruby-2.1.1/bin/ruby"
irb: "/usr/local/rvm/rubies/ruby-2.1.1/bin/irb"
gem: "/usr/local/rvm/rubies/ruby-2.1.1/bin/gem"
rake: "/usr/local/rvm/rubies/ruby-2.1.1/bin/rake"
environment:
PATH: "/usr/local/rvm/gems/ruby-2.1.1/bin:/usr/local/rvm/gems/ruby-2.1.1#global/bin:/usr/local/rvm/rubies/ruby-2.1.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local.rvm/bin:/usr/local/rvm/bin"
GEM_HOME: "/usr/local/rvm/gems/ruby-2.1.1"
GEM_PATH: "/usr/local/rvm/gems/ruby-2.1.1:/usr/local/rvm/gems/ruby-2.1.1#global"
MY_RUBY_HOME: "/usr/local/rvm/rubies/ruby-2.1.1"
IRBRC: "/usr/local/rvm/rubies/ruby-2.1.1/.irbrc"
RUBYOPT: ""
gemset: ""

Ruby gem running forever and Ruby, gem path error

I have problem with my gem and Ruby command, I think it's because of path problem.
gem install jekyll
takes for a long time to run, and outputs an error message:
ERROR: Could not find a valid gem 'jekyll' (>= 0)
Unable to download data from https://rubygems.org/ - too many connection resets(https://s3.amazonaws.com/production.s3.rubygems.org/latest_specs.4.8.gz)
I entered which ruby, which output:
/usr/local/bin/ruby
If I enter which gem, it prints out:
gem () {
typeset result
(
typeset rvmrc
rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
then
rvm_rvmrc_files+=("${rvm_prefix}/.rvmrc")
fi
for rvmrc in "${rvm_rvmrc_files[#]}"
do
[[ -s "${rvmrc}" ]] && source "${rvmrc}" || true
done
unset rvm_rvmrc_files
command gem "$#"
) || result=$?
hash -r
return ${result:-0}
}
Enter whereis gem, prints out:
/usr/bin/gem
Does anyone know how to fix it? I've tried for a long time and get confused.
UPDATE:
Enter gem env I got:
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.3
- RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-darwin13.0.0]
- INSTALLATION DIRECTORY: /Users/lijung/.rvm/gems/ruby-1.9.3-p374
- RUBY EXECUTABLE: /usr/local/Cellar/ruby/2.0.0-p247/bin/ruby
- EXECUTABLE DIRECTORY: /Users/lijung/.rvm/gems/ruby-1.9.3-p374/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-13
- GEM PATHS:
- /Users/lijung/.rvm/gems/ruby-1.9.3-p374
- /usr/local/bin/gem
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
enter rvm info:
ruby-1.9.3-p374:
system:
uname: "Darwin chi.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64"
system: "osx/10/x86_64"
bash: "/usr/local/bin/bash => GNU bash, version 4.2.37(2)-release (i386-apple-darwin12.2.0)"
zsh: "/bin/zsh => zsh 5.0.2 (x86_64-apple-darwin13.0)"
rvm:
version: "rvm 1.18.3 (master) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]"
updated: "9 months 18 days 11 hours 37 minutes 54 seconds ago"
ruby:
interpreter: "ruby"
version: "2.0.0p247"
date: "2013-06-27"
platform: "x86_64-darwin13.0.0"
patchlevel: "2013-06-27 revision 41674"
full_version: "ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin13.0.0]"
homes:
gem: "/Users/lijung/.rvm/gems/ruby-1.9.3-p374"
ruby: "/Users/lijung/.rvm/rubies/ruby-1.9.3-p374"
binaries:
ruby: "/usr/local/bin/ruby"
irb: "/usr/local/bin/irb"
gem: "/usr/local/bin/gem"
rake: "/usr/local/bin/rake"
environment:
PATH: "/usr/local/bin:/usr/local/sbin:/Users/lijung/.rvm/gems/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/gems/ruby-1.9.3-p374#global/bin:/Users/lijung/.rvm/rubies/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Postgres.app/Contents/MacOS/bin"
GEM_HOME: "/Users/lijung/.rvm/gems/ruby-1.9.3-p374"
GEM_PATH: "/usr/local/bin/gem"
MY_RUBY_HOME: "/Users/lijung/.rvm/rubies/ruby-1.9.3-p374"
IRBRC: "/Users/lijung/.rvm/rubies/ruby-1.9.3-p374/.irbrc"
RUBYOPT: ""
gemset: ""
The first thing I see that is a "really bad thing" when using RVM is:
PATH: "/usr/local/bin:/usr/local/sbin:/Users/lijung/.rvm/gems/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/gems/ruby-1.9.3-p374#global/bin:/Users/lijung/.rvm/rubies/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Postgres.app/Contents/MacOS/bin"
Even with how Stack Overflow formats this you can see that the RVM initialization isn't correct. RVM must be the first thing in your path. Look in your ~/.bash_profile or ~/.bashrc file and adjust the PATH manipulations so it comes first, then close the terminal window and reopen it. Checking the PATH should look something like:
"/Users/lijung/.rvm/gems/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/gems/ruby-1.9.3-p374#global/bin:/Users/lijung/.rvm/rubies/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/bin:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Postgres.app/Contents/MacOS/bin"
The path is the chain of directories used by your shell when looking for a command. Your current path is telling the shell to find commands in /usr/local/bin and /usr/local/sbin first, which means it will find all Ruby-related commands in that directory first, which are NOT the ones that RVM installed for you.
Fixing the RVM initializer so it runs at the right point in your ~/.bash_profile or ~/.bashrc is the first step.
Your RVM is out of date too. Every couple weeks you should run rvm get stable to make sure you've got the latest settings and bug-fixes. Once your path is straightened out you can run that.
The error:
Unable to download data from https://rubygems.org/ - too many connection resets...
is indicative of internet problems between you and your server. Usually that will be fixed on its own. If it doesn't heal itself in a reasonable time, try restarting your machine, which will give the IP stack a chance to restart and flush all its caches; Though that code is well tested, there are still times it can lose it's mind and do dumb things. The reset is a poke in its eye which gets its attention. If THAT doesn't fix it consider calling your ISP.
I be able to use Ruby, that I've downloaded from brew? How can I set my gem path to the right path?
Deal with things in the right order. You can't use your Ruby as it's currently configured because your gems are not correctly associated with the right Ruby version and any changes you make to the Ruby installations will only result in confusion and mayhem. Once you have the path corrected and RVM running correctly, then it's a very simple RVM command to enable other Homebrew Rubies:
rvm use system --default
At that point, RVM will step out of the way and your other Rubies will be accessible via the PATH chain. You have to manage which Ruby version will be executed at that point.
Avoiding that hassle is why we use RVM or rbenv; They can easily install multiple Ruby versions and let you switch between them with a simple command, or even automatically when you chdir into a directory, if you set them up to do so. Brew only muddies the water, and trying to use a Brew installed Ruby was the source of your problem, so I'd recommend seriously rethinking that decision.
Finally, because you don't seem to understand what you're doing, and you're on Mac OS X, I'd recommend fixing this path problem, then backing away from the computer, READ ALL THE RVM PAGES until you REALLY understand what it does, then carefully make changes. Don't trust what other sites say about installing RVM, trust what the RVM authors say first. The authors know what works best for using it.
You might want to look into using JewelryBox also.

/usr/bin/env ruby_noexec_wrapper fails with no file or directory

When I try to start chef-solr as service it's failing with the following error
# service chef-solr start
Starting chef-solr: /usr/bin/env: ruby_noexec_wrapper: No such file or directory
[FAILED]
But when I run it manually from command line it's running successfully
# chef-solr -d -c /etc/chef/solr.rb -L /var/log/chef/solr.log -P /var/run/chef/solr.pid
# echo $?
0
# ps -ef | grep chef
root 2691 1 12 04:19 ? 00:00:01 java -Xmx256M -Xms256M -Dsolr.data.dir=/var/lib/chef/solr/data -Dsolr.solr.home=/var/lib/chef/solr/home -jar /var/lib/chef/solr/jetty/start.jar
Here is my rvm info
# rvm info
ruby-1.9.3-p194:
system:
uname: "Linux Console 2.6.32-220.el6.x86_64 #1 SMP Wed Nov 9 08:03:13 EST 2011 x86_64 x86_64 x86_64 GNU/Linux"
bash: "/bin/bash => GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)"
zsh: " => not installed"
rvm:
version: "rvm 1.15.6 (stable) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]"
updated: "7 hours 1 minute 51 seconds ago"
ruby:
interpreter: "ruby"
version: "1.9.3p194"
date: "2012-04-20"
platform: "x86_64-linux"
patchlevel: "2012-04-20 revision 35410"
full_version: "ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]"
homes:
gem: "/usr/local/rvm/gems/ruby-1.9.3-p194"
ruby: "/usr/local/rvm/rubies/ruby-1.9.3-p194"
binaries:
ruby: "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby"
irb: "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/irb"
gem: "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/gem"
rake: "/usr/local/rvm/gems/ruby-1.9.3-p194/bin/rake"
environment:
PATH: "/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/lib64/qt-3.3/bin:/usr/java/default/bin:/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/usr/bin:/root/bin"
GEM_HOME: "/usr/local/rvm/gems/ruby-1.9.3-p194"
GEM_PATH: "/usr/local/rvm/gems/ruby-1.9.3-p194:/usr/local/rvm/gems/ruby-1.9.3-p194#global"
MY_RUBY_HOME: "/usr/local/rvm/rubies/ruby-1.9.3-p194"
IRBRC: "/usr/local/rvm/rubies/ruby-1.9.3-p194/.irbrc"
RUBYOPT: ""
gemset: ""
Here are the corresponding environmental variables
declare -x GEM_HOME="/usr/local/rvm/gems/ruby-1.9.3-p194"
declare -x GEM_PATH="/usr/local/rvm/gems/ruby-1.9.3-p194:/usr/local/rvm/gems/ruby-1.9.3-p194#global"
declare -x IRBRC="/usr/local/rvm/rubies/ruby-1.9.3-p194/.irbrc"
declare -x MY_RUBY_HOME="/usr/local/rvm/rubies/ruby-1.9.3-p194"
declare -x PATH="/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/lib64/qt-3.3/bin:/usr/java/default/bin:/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/usr/bin:/root/bin"
declare -x RUBY_VERSION="ruby-1.9.3-p194"
How to get this issue resolved?
make sure all the variables all set correctly, especially PATH and GEM_PATH, you can use this code to set the environment for you:
source /usr/local/rvm/environments/ruby-1.9.3-p194
add it in the service before chef-solr is run
My problem was similar, and so was my answer:
My problem was
Permission denied - /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper
ruby_noexec_wrapper was in ruby-1.9.3-p194#global not in the listed path
My solution was
source /usr/local/rvm/environments/ruby-1.9.3-p194#global
I upvoted mpapis because his answer was critical in finding mine. Feel free to upvote him rather than me. Just adding an additional answer to try and help anybody with a similar problem.
Answer not related to chef, but may help in future.
I had a similar issue, but since I was following a tutorial to setup thin in RVM. I fixed by using wrapper generated by RVM for thin service
/home/thin/.rvm/bin/bootup_thin
therefore changed line in init script
DAEMON=/home/thin/.rvm/gems/ree-1.8.7-2012.02/bin/thin
to
DAEMON=/home/thin/.rvm/bin/bootup_thin
Post on RVM wrappers RVM and thin, root vs. local user
I try all these answers, all failed. But I found another way to solve this problem, could be helpful:
gem install rubygems-bundler
You can also find answer from noexec library
I got this problem after installing ruby 2.0 on my mac. Part of that was I installed the latest rvm
rvm get stable
Then I started getting this error. Maybe I ran some 'gemset pristine's after this.
In any event, for me, this worked. WARNING! If you proceed as I have done, your gemsets for the ruby in question will get completely removed and rebuilt. Maybe you want a fresh backup? But this is the hammer.
# WARNING!!! THIS RECIPE IS POTENTIALLY DESTRUCTIVE!
rvm remove ruby-1.9.3-p194 # this will remove the gemsets for this version as well
rvm install ruby-1.9.3-p194 # time for coffee
rvm use ruby-1.9.3-p194
rvm gemset create aura-rover-config # my gemset name
rvm use ruby-1.9.3-p194#aura-rover-config # do I need to do this? Can't 'member
bundle
# now it all works
The fun part of this was, all the little hacks I made in my installed gemsets, those got blown away. MAKE A BACKUP

Resources