system("rvm 2.5.3 do ruby -v") leads to Warning! PATH is not properly set up - rvm

Before marking this as duplicate let me explain:
When running rvm 2.5.3 do ruby -v, everything works well:
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin17]
e.g. ruby -v gives ruby 2.7.0dev (2019-03-18 trunk 67296) [x86_64-darwin17]
But when running ruby -e "system('rvm 2.5.3 do ruby -v')" I get the big old Warning! PATH is not properly set up message (even though it executes correctly).

Solution was to add set -gx PATH $HOME/.rvm/bin $PATH to my ~/.config/fish/config.fish.
Hope it helps others.

Related

RVM not changing loaded ruby

I have an .rvmrc file:
rvm use 1.9.3-p286#refinery --create
and changing to that folder yields:
Using /Users/neil/.rvm/gems/ruby-1.9.3-p286 with gemset refinery
$ ~/code/visioneng/ master* ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
$ ~/code/visioneng/ master*
However, this clearly isn't what I asked for. What gives?
check if you do not overwrite PATH in any of your shell scripts/functions/aliases

$ Command not found with "rails new app -m myfile.rb"

I'm trying to use the MongoID-Devise generator template by doing this under Ubuntu and using RVM:
rails new myapp -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-mongoid-devise-template.rb
I've also tried to download the file and do the generation locally, but in both cases, I get:
$: command not found
As according to the guides: Application Template, I'm using the command/options correctly...
EDIT:
The following commands gives me the following results:
rails -v --> Rails 3.1.3
ruby -v --> ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
The "$" you see at the beginning of the command is actually a convention that indicates a Unix console prompt. Don't include the "$".

Problem with RVM use

I am having trouble with using rvm use in zsh. Whenever I do rvm use 1.9.2 or other ruby version, it gives confirmation as Using /home/kxhitiz/.rvm/gems/ruby-1.9.2-p290
But when I do rvm list ruby 1.9.2 is not selected. This works fine in bash. That means I can go to bash and select ruby version I need, and I can come back to zsh to use it.
So that means if I have to change ruby from list of rubies I have installed, I have to go to bash to select it and once selected in bash, I can see it selected in zsh as well.
Any solution would be highly appreciated.
Ok, I did fixed it by adding following line at the end of my ~/.zshrc file
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Cheers!

"uninitialized constant Encoding" using rvm, ruby 1.9.2, bundler and passenger

I am at wit's end here and am turning to you all for some help on this f*#$^ encoding issue.
I am running on a private server with root permissions on Dreamhost. Here is a bit about my environment and versions.
$ `which ruby` -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
$ `which bundle` -v
Bundler version 1.0.15
$ `which rails` -v
Rails 3.0.9
Aside from this error, my rails app runs fine without issue. However, when I try to change the encoding a string by using the encode method it:
NoMethodError: undefined method `encode' for "foobar":String
encode should be defined but it is not! Encoding is found if I try in irb:
$ irb
ruby-1.9.2-p180 :001 > Encoding
=> Encoding
ruby-1.9.2-p180 :002 > "foobar".encode('utf-8')
=> "foobar"
But if I try using the rails console through bundle exec, Encoding is not found:
$ bundle exec rails c staging
Loading staging environment (Rails 3.0.9)
ruby-1.9.2-p180 :001 > Encoding
NameError: uninitialized constant Encoding
from /[REDACTED]/shared/bundle/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from (irb):1
ruby-1.9.2-p180 :002 > "foobar".encode('utf-8')
NoMethodError: undefined method `encode' for "foobar":String
Obviously the setup is not loading something correctly but I am not sure where to look to figure it out. What am I missing here?
UPDATE 6/19/2011
As Ryan Bigg pointed out, it is curious that the directory path for the gems is 1.8. However, running bundle exec shows that bundler is using the correct ruby and rails versions:
$ bundle exec which ruby
/path/to/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
$ bundle exec `which ruby` -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
$ bundle exec which rails
/path/to/shared/bundle/ruby/1.8/bin/rails
$ bundle exec `which rails` -v
Rails 3.0.9
Clearly something is wonky here… I just don't know what.
UPDATE 6/26/2011
Seamus asked for the $LOAD_PATH…
UPDATE 6/26/2011 (later)
Seamus asked for the Gemfile.lock and the pp ENV… In the ENV output, I found that the GEM_PATH was not correct. In my staging.rb environment file, I have:
GEM_HOME = "/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180#[REDACTED]"
GEM_PATH = "/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180#[REDACTED]:/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180#global"
…which is obviously not being honored. Nowhere else in my code is there a mention of GEM_HOME or GEM_PATH
UPDATE 6/27/2011
Seamus asked for the .bundle/config contents…
UPDATED same idea (that GEM_HOME is messed up), but more suggestions
Your GEM_HOME is messed up, possibly because your PATH is messed up. You could try setting the following environment variable in your shell
$ export PATH=[your current path but with rvm's ruby 1.9 at the front]
Then run
$ bundle install
If that doesn't work, try also setting this in your shell
$ export GEM_HOME=[your ruby 1.9 gem home]
and then re-run
$ bundle install
New ideas from this answer: Using RVM, bundler does not install in proper gemset when gems are installed in a different ruby version

RVM & Unicorn deploy

My RVM is installed as root.
When I'm trying to start unicorn socket, it prints
user#9001-3:~$ /etc/init.d/unicorn start
Starting myapp app: /usr/bin/env: ruby: No such file or directory
unicorn.
But if I type
user#9001-3:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
/usr/local/rvm/gems/ruby-1.9.2-p180/bin/unicorn path exists.
My unicorn config: https://gist.github.com/1010519
/etc/init.d/unicorn doesn't know where to find Ruby because it's managed via RVM. Normally, your .bashrc or similar file is executed and sets up the environment; this doesn't happen in init scripts (or likely anything else executed by root).
The solution is to use wrappers. For example, to create a binary called system_ruby that loads up RVM's 1.9.2p180 environment and then executes ruby, execute the following:
rvm wrapper ruby-1.9.2-p180 system ruby
For more information and more details, check out this answer of mine, which addresses a similar problem.
Symlink also works,
which ruby<your version>
ln-s /ruby/path/ruby<your version> /ruby/path/ruby
Type :
which ruby (show the ruby bin path) then type this : ln -s (change_to_ruby_path) /usr/bin/env/ruby (construct the correct access for your system)
I had the same problem and this for me
rvm --default use <version>