r/ruby • u/Ayano-Keiko • Apr 26 '26
venv in ruby
Finnally, I get used of ruby bundle. The step is following
- set the vendor path
bundle init
bundle config set --local path 'vendor/bundle'
-
add gem to
Gemfilefile -
install gem package
bundle install
- run the ruby script
bundle exec ruby ./script.rb
Is these any way I can install ruby packages in current project folder like Python venv. I only know about gem install <custom-gem> --user-install which install in $HOME/.gem/ruby/2.6.0/gems/. AI said I should use bundler and Gemfile. But it seems very comfused and do not work well with gem file ( it only work with package uploaded on https://rubygems.org/
3
Upvotes
5
u/azrazalea Apr 26 '26
You can use vendor. bundle config set --local path 'vendor/bundle' followed by bundle install.
1
u/fglc2 Apr 26 '26
bundle config path foowill install gems into the named path.That said, why do you want gems to be installed in the current project’s folder?
3
u/monfresh Apr 26 '26
It would be helpful if you can explain in more specific detail what exactly you're trying to do, and what specific errors you are seeing.
It sounds like you are trying to install a gem that you built, or some other gem that is not published on rubygems.org. Is that right?
Also, you mentioned Ruby 2.6.0, which is very very old. Are you perhaps on macOS, and you're trying to use the system Ruby (the Ruby version that came preinstalled on macOS), instead of a newer version like Ruby 4.0?
1
u/waltz Apr 26 '26
You can specify a gem with a path arg in the gemfile: https://bundler.io/man/gemfile.5.html#PATH
1
u/Rich-University1473 Apr 26 '26
I use bundler and binstubs, similar to what is described in this blog post. https://wolfgangrittner.dev/bundle-exec-be-gone/
1
u/RedditShmeddit2 Apr 27 '26
You could use devenv for this - https://devenv.sh . Always found setup and config super easy
1
u/codesnik Apr 27 '26
trying to force paradigms from one language and package manager to another rarely helps.
bundler does the right thing. Gems are not that heavy to share between ruby versions. Also _not_ bundling them in the project folder, but into the ruby folder, helps later when you'd need to upgrade your ruby version, no chance of incompatible compiled leftovers.
1
u/Professional_Mix2418 Apr 26 '26
I don’t understand what is confusing about it. Firstly you’d want a version manager like mise or asdf-vm to deal with your versions. Then you can have a local ruby version for each project easily. It really doesn’t matter, actually is rather efficient, that gems are installed once. Why would you want it duplicated?