6

I made similar question for npm here: npm equivalent of `pip install -r requirements.txt`

This is for gem.

What are the gem equivalent of:

pip freeze > requirements.txt
pip install -r requirements.txt
Community
  • 1
  • 1
Ron
  • 7,588
  • 11
  • 38
  • 42

2 Answers2

7

There isn't a direct comparison in Ruby, but we have something very similar. Look at the bundler gem for how to write your list of required gems into a Gemfile and automatically generate a Gemfile.lock which contains the current versions installed.

Bruno Duyé
  • 1,014
  • 11
  • 13
Spooner
  • 427
  • 7
  • 7
  • Question was to have equivalent of pip freeze... In translation from python ecosystem: how to create Gemfile (or Gemfile.lock) for current gem environment (all packages in current `gem env`). I did not find way how to use bundler to transform `gem list` into something what can be used with `gem install ...` – Juraj Michalak Sep 05 '22 at 11:20
2

My solution is:

serverA: $ gem list | tr -s ',[ ()]' ' ' | awk '$2 ~ /[0-9]\.[0-9]/ {print $1" -v "$2; next} $3 ~ /[0-9]\.[0-9]/ {print $1" -v "$3}' > reqs.txt

serverB: $ cat reqs.txt | while read  l; do echo "=== Installing 'gem install $l' ===";  gem install $l --conservative || exit 1; done

My situation was. On server "A" I have 3rd party developed ruby scripts with many dependencies and no Gemfile. I have to use those same ruby scripts on server "B". How can I easily "copy" ruby env with all possibly required gems to server "B" (same versions).

Juraj Michalak
  • 1,138
  • 10
  • 9