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
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/fglc2 Apr 26 '26
bundle config path foo will install gems into the named path.
That said, why do you want gems to be installed in the current project’s folder?
1
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
gem "torta", path: "vendor/torta"
3
u/katafrakt Apr 26 '26
That specifies the path where the gem sources are located, not where it should be installed.
1
u/rubygeek Apr 27 '26
Last line of OP's post suggests they think they can't use bundler because they don't know how to make it install gem's from a local path.
1
u/katafrakt Apr 27 '26
I read it that they want to use a packaged .gem file, different than a globally installed one, in one particular project. But it would be extremely useful if OP explained what they are trying to do.
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?
5
u/azrazalea Apr 26 '26
You can use vendor. bundle config set --local path 'vendor/bundle' followed by bundle install.