1

I'm trying to make a new rails application with a intent not to install gems as system gem as possible. At first I installed bundler as system gem, made a Gemfile which specified only rails and executed 'bundle install'. (In my opinion, bundler is OK to be a system gem...)

mkdir -p /opt/rails/rails_app
cd /opt/rails/rails_app
gem install bundler
bundle init
cp Gemfile /tmp
sed 's/#gem rails/gem rails/' /tmp/Gemfile > Gemfile
bundle config build.nokogiri --use-system-libraries
bundle install --path vendor/bundle

Rails was installed as a 'local gem' which is limitted within /opt/rails/rails_app.

Then I tried to make a rails application by 'rails new'.

bundle exec rails new . --skip-bundle

This caused replacing the Gemfile, so a message was shown like this.

Overwrite /opt/rails/rails_app/Gemfile? (enter "h" for help) [Ynaqdh]

Usually what should be done is only type 'y'. However, this time, I want to do that automatically for making a vagrant's provision script.

So I tried expect but it never worked. All results were either timeout or syntax error:

expect -c "
spawn bundle exec rails new . --skip-bundle --quiet
expect \"Overwrite /opt/rails/rails_app/Gemfile? (enter \"h\" for help) \[Ynaqdh\] \"
send \"y\r\"
"

I couldn't find where is wrong in this code and other solutions than using expect.

3
  • Have you looked at rvm or rbenv? They let you install Rubies and gems (including Rails) to your home directory. No root privileges are needed. Commented Jul 23, 2015 at 21:00
  • No, I didn't. I'll try them.Thanks.
    – cul8er
    Commented Jul 24, 2015 at 2:24
  • About the solution with expect, I got answer at another question: stackoverflow.com/questions/31601455/…
    – cul8er
    Commented Jul 25, 2015 at 3:18

2 Answers 2

1

It looks like there is a skip_gemfile option in the rails generator

0

You can use bundle install --path [directory] to install you gems locally inside your app. Typicall you would use './vendor/bundle' as your directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.