Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6918147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:49:18+00:00 2026-05-27T09:49:18+00:00

I am trying to install ruby 1.9.2 from a ruby script using rvm which

  • 0

I am trying to install ruby 1.9.2 from a ruby script using rvm which is installed from the same script. The problem I have is sourcing .bashrc within the script so that the path to rvm is available within the script. The following works:

#!/usr/bin/env ruby

%x[bash -c "bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)" ]
%x[ln -s /usr/local/rvm/ .rvm]
%x[echo "[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\""  >> ~/.bashrc]

But I am not able to execute from within this ruby script

 source .bashrc

I’ve tried

  %x[bash -c "bash <(. .bashrc)"]

I’ve also tried running separately the line that the script added to .bashrc

 %x[ bash -c "bash <(source  \"$HOME/.rvm/scripts/rvm\" )"   ]

I have tried sessions but the puts below gives a blank response to “which rvm”.

 require 'rubygems'
 require 'session'
 bash = Session::Bash.new
 stdout, stderr = bash.execute 'source .bashrc'
 puts "which rvm = " + %x[which rvm 2>&1].inspect

Am I looking at this all wrong? Is trying to source .bashrc within a ruby script and using the resulting environment to execute subsequent commands possible?

Update –

Using Ian’s approach below with bash -ic I was able to get the ruby script working. But all subsequent shell commands that need to see the new environment have to be run with bash -ic as well. Here is the working script:

 #!/usr/bin/env ruby
 %x[bash -c "bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)" ]
 %x[ln -s /usr/local/rvm/ .rvm]
 %x[echo "[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\""  >> ~/.bashrc]
 %x[bash -ic "bash <(. ~/.bashrc); rvm install ruby-1.9.2-p290; rvm 1.9.2-p290 --default;"]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:49:18+00:00Added an answer on May 27, 2026 at 9:49 am

    I believe you need to pass the -l flag to the invocation of bash from ruby, which will make the embedded bash shell act as a login shell and read .bashrc and .bash_profile. See also the ref manual for more details.

    Update

    Sorry, I meant the -i flag, not -l. I tried this:

    [~/temp/rubytest] 
    ian@ian-desktop2 $ echo "export FOO=fubar" >> ~/.bashrc
    [~/temp/rubytest] 
    ian@ian-desktop2 $ irb
    jruby-1.6.5 :001 > %x[ bash -c "env | grep FOO" ]
     => "" 
    jruby-1.6.5 :003 > %x[ bash -ic "env | grep FOO" ]
     => "FOO=fubar\n" 
    jruby-1.6.5 :004 > %x[ bash -ic "echo 'export FOO2=fubar2' >> ~/.bashrc ; env | grep FOO" ]
     => "FOO=fubar\n" 
    jruby-1.6.5 :005 > %x[ bash -ic "echo 'export FOO2=fubar2' >> ~/.bashrc ; source /home/ian/.bashrc ; env | grep FOO" ]
     => "FOO=fubar\nFOO2=fubar2\n" 
    jruby-1.6.5 :006 > 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to install ruby-mp3info. I have the following URL from which I
I have been trying to install ruby 1.9.2 using rvm but I'm unable to
I am trying to install Ruby 1.9.3 but am having problems. I installed RVM,
I'm trying to install bcrypt-ruby on Windows Vista. So far, I have been able
I'm trying to install the paperclip plugin with the following command: ruby script/plugin install
I have been trying to use the ruby-git gem to make commits etc from
I am currently trying to install the gem nfoiled , which provides a ruby
I'm trying to install Ruby 1.9.3 with RVM. [21:43:24] [william@enterprise ~]$ rvm install 1.9.3-p0
I'm trying to run rails from my root directory (Im using RVM) and I
I'm trying out rvm, and installed ruby 1.9.2 and rails 3 with it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.