Rvm Is Not Working Over Ssh

RVM is not working over SSH

From the ssh man page:

If command is specified, it is executed on the remote host instead of
a login shell.

This should mean that your .bashrc won't get sourced, so RVM doesn't get set up.

Solution

This did the trick in the end:

ssh <host> bash --login -c <command>

Start bash as a login shell through SSH and then start the RVM installed Ruby via SSH's -c option.

rvm installation not working: RVM is not a function

You are not using an login shell.

The process of enabling the login flag is described here, also some details on what a login shell is can be found here.

Thus, you need to check the option "Run as login shell" in the Gnome terminal's settings. It is required to open new terminal after this setting the flag.

Sometimes it is required to set the command to /bin/bash --login.


For remote connections it is important to understand the differene between running interactive ssh session and executing single commands.

While running ssh server and then working with the server interactively you are using login shell by default and it's all fine, but for ssh server "command" you are not using login shell and it would be required to run it with ssh server 'bash -lc "command"'.

Any remote invocation can have the same problem as executing single command with ssh.

How to change rvm gemset over ssh on os x server

Ok, after all.

def exec_via_bash(line)
puts %Q(#{line})
exec = 'bash -c "#{line}"'
puts `#{exec}`
end

def RubySetup
# reload bash profile
homedir = ENV['HOME']
exec_via_bash %Q(source #{homedir}/.bash_profile);

exec_via_bash %Q(source #{homedir}/.bashrc);

# reload ruby
exec_via_bash %Q(source #{homedir}/.rvm/scripts/rvm);

ruby_setup = %Q([[ -s "#{homedir}/.rvm/scripts/rvm" ]] && source "#{homedir}/.rvm/scripts/rvm")

puts ruby_setup
ruby_setup
end

if ARGV.empty?
puts "there is not enough arguments passed. maybe you forget ruby file to exec?"
exit(1)
end

ruby_script_path = ARGV.shift;

exec_file_absolute_path = File.expand_path(ruby_script_path)

unless File.exists? exec_file_absolute_path
puts "file #{exec_file_absolute_path} doesn't exists!"
exit(1)
end

exec_file_directory = File.dirname(exec_file_absolute_path)
exec_bundle = %Q'bundle exec ruby #{exec_file_absolute_path}' + ' ' + ARGV.join(' ')

# change directory
Dir.chdir(exec_file_directory);
# print %x(ls);

# configure gemset name
version = %x(cat .ruby-version).strip;
gemset = %x(cat .ruby-gemset).strip;
change_rvm_gemset = %Q(rvm use #{version}\@#{gemset});

ruby_setup = RubySetup()

exec_bash_login_line = [ruby_setup, change_rvm_gemset, exec_bundle].join ' && ';
puts 'exec bash login line: ' + exec_bash_login_line
forced = %Q(bash --login -c '#{exec_bash_login_line}');
puts forced, "\n";
puts %x(#{forced});

ok, this script is not a kind of beauty, but it works well.

Example of usage?

ruby script.rb ~/bla/bla/bla/run_your_program.rb --first_argument --second_argument a,b,c --etc

As I said before:

I've already on the server via ssh.

So, I need to run scripts via launchd.

And I should do it with

# part of launchd worker
<string>bash</string>
<string>-c</string>
<string>ruby ~/PathToCharmScript.rb -r a</string>

P.S:

Please, help me with improvements of this script for others!

Here is a gist: wow_this_works

AWS EC2 and rvm ssh

I've run into this problem before and there are 2 ways to solve it.

The first way is to log in directly as the deployer user to the instance. This might mean having to create a ssh keypair (see ssh-keygen -t rsa). Then you can log in with ssh deployer@ec2.instance.address This way the rvm will be loaded directly to the deployed user's shell.

A second way is not to use the dash when su to the deployed user account.

When you use the dash then you load your own bashrc vs that particular user's bashrc.

So sudo su deployer

How to create an RVM environment on a server through net-ssh?

Basically the RVM environment need to be loaded to be able to script it remotely.
https://rvm.io/workflow/scripting/

You can run the following command with net-ssh to do so:

conn.exec!("source "/usr/local/rvm/scripts/rvm; rvm --create ruby-1.9.3-p286@my_project_name")

It will create your environment and associated gemset.

ruby version on remote server is not changed

As you've guessed, rvm needs to be installed for the deploy user. It's a per-user setting.

Edit: Problem already solved here

Installing RVM via capistrano V3, CURL throws garbage in terminal

Here is my complete Install Ruby function that I use to build jenkins servers. Keep in mind I use Capistrano V2. Enjoy.

task :install_ruby, roles => :app  do
run "yum --exclude=*.i386 --exclude=*.i586 install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel libxml2-devel libxslt-devel"
run "bash -s stable < <(curl -k -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)"
run "source /etc/profile"
run "rvm install 1.9.3 --autolibs=enabled"
run "rvm use 1.9.3 --default"
run "gem install capistrano", { :shell => 'bash'}
run "gem install railsless-deploy", { :shell => 'bash'}
run "gem install ntlm-http; true", { :shell => 'bash'}
run "gem install domain_name", { :shell => 'bash'}
run "gem install webrobots", { :shell => 'bash'}
run "gem install mechanize", { :shell => 'bash'}
end


Related Topics



Leave a reply



Submit