Search code examples
ruby-on-railsbashbundler

How to use specific bundler version inside bash shell script


I'm running some bundle install and rake migrations inside a bash script, but the bundle version used is not the one I need. How can I make it use a different bundle version

#!/bin/bash

function run_setup {
    echo "Running setup and DB migrations"
    cd $cwd/apps/rails_app
    gem install bundler -v 1.3
    bundle -v                      # SHOWS version 1.15
    bundle install                 # Errors out
    rake db:migrate
}

When I run the bash function above, bash uses bundle version 1.15. I need it to use the 1.3 version it is installing before calling bundle install. Thanks.


Solution

  • You can pass the version to bundler command like this:

    bundle _X.X.X_ install
    

    So your function would look something like this:

    #!/bin/bash
    
    function run_setup {
        echo "Running setup and DB migrations"
        cd $cwd/apps/rails_app
        gem install bundler -v 1.3
        bundle _1.3_ install
        rake db:migrate
    }