When I run gem cleanup -d it lists several gem versions that are dependencies. The gems that depend on them are listed in the Gemfile in a jekyll install I have via my github repo, which I suspect is why gem doesn't see the dependencies.
Is there a way to tell gem to look at the jekyll install's Gemfile for dependencies?
Or is it actually another problem?
TIA.
Related
I tried to build a local gem and was surprised to find that even the dependency gems were not installed I can still run gem build .gemspec successfully.
For example, my .gemspec has declared the following dependency and I am sure they are not installed yet. But gem build succeeded and only after I run gem install to install my local gem will those gems be installed as well.
spec.add_runtime_dependency "terminal-notifier-guard"
spec.add_dependency "activesupport", "~> 4.2.0"
From c/c++ background, I find that is a bit confusing. I know ruby is interpreted/dynamic (whatever that means) language, the script will be interpreted when I actually run it. But what does gem build .gemspec build then? What criteria will it use to determine the build is successful (e.g. except for syntax error in codes)?
Dependent gems are installed as remote dependency and are installed when the gem is being installed or during bundle in case of rails. You cannot make it local dependent since it cannot be accessed by others.So your mention of
spec.add_dependency "activesupport", "~> 4.2.0"
in .gemspec file is correct.
.gemspec: Gem build information is stored here. It is a standard format for describing all of the information that gets packed with gems then deployed to rubygems.org.
gem build hola.gemspec
It's just used to build and you need to run gem install to test it.
I cannot require a custom gem I developed to a ruby project. I use RVM. Here's what I've done:
I added gem locally via Gemfile:
gem 'my-gem', git: 'https://github.com/username/my-gem.git'
I installed the gem:
bundle
Fetching https://github.com/username/my-gem.git
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Using my-gem 0.1.0 https://github.com/username/my-gem.git (at master#dcdac02)
Using bundler 1.11.2
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
I confirmed it was installed:
bundle show my-gem
/Users/myuser/.rvm/gems/ruby-2.2.2/bundler/gems/my-gem-dcdac02a8b69
I confirmed my gem paths:
GEM PATHS:
- /Users/myuser/.rvm/gems/ruby-2.2.2
- /Users/myuser/.rvm/gems/ruby-2.2.2#global
When I run gem list, my gem is missing. When I require 'my-gem', the gem cannot be found.
When I run gem which my-gem, I get:
ERROR: Can't find ruby library file or shared library my-gem
I'm not really sure what else to try. Any ideas?
Rubygems have no concept of git installed gems, so Bundler includes a specific mechanism for loading these paths into the GEMPATH, you need to do the following before you can require them:
require 'bundler'
Bundler.setup
See the Bundler git gems docs for more info.
I would make sure the installed version of the gem has all the files you expect, especially lib and its contents. This past discussion might help you:
gem which cannot find gem despite it being installed
I found a similar issue
bundle show kubernetes_metadata_filter
/fluentd/vendor/bundle/ruby/2.3.0/bundler/gems/fluent-plugin-kubernetes_metadata_filter-0cd7e29eacec
while the rest of my gems were install here:
/fluentd/vendor/bundle/ruby/2.3.0/gems/
notice the subtle difference between 2.3.0/bundler/gems/... and 2.3.0/gems/......
HACKY SOLUTION:
after bundle install, i did the following:
gem install specific_install
gem specific_install -l <url to a github gem>
That did the trick and installed the gem to the gems directory, and not just bundler. I beleive the correct fix is the project needs to require bundler on startup, then it will get the bundler installed gems as well, but not all projects are well suited for that solution. good luck!
How can I make a typical gem setup (as generated by bundle gem) run a customize version of bundler?
I've added:
#group :development do
gem "bundler", github: 'pjump/bundler'
#end
to my Gemfile (with or without the the hash symbols), and bundle install works, but bundle exec keeps telling me that the bundler repo is not yet checked out. The only way I can make it work for now is by installing the customized version with gem istall and not specifying a bundler dependency in the package at all.
Bundler isn't able to bootstrap itself from a Gemfile, so adding a customized version to your Gemfile will not do what you want. Installing it with gem install is the correct solution (or running rake install from the forked Bundler repo directory, which builds and installs the gem in one step).
i've read the documentation from rubygems site, but i guess the "gem install" command always reinstall, recompile everything, even if the same version already installed..
how to make gem install command only install when needed?
It looks like the --conservative flag will make the gem command do what you want.
gem install rake --conservative
From the documentation gem install --help:
--conservative Don't attempt to upgrade gems already meeting version requirement
You may want to use something external like gembundler to handle project’s gem installation.
If you must use rubygems directly for this, a command like
ruby -e "puts `gem install GEMTOINSTALL` if(`gem list --no-versions | grep GEMTOINSTALL`) == ''"
would do the job.
That is why we use bundle install. This command will look into the gemfile for the gems.
This Gemfile says a few things. First, it says that bundler should look for gems declared in the Gemfile at http://rubygems.org. You can declare multiple Rubygems sources, and bundler will look for gems in the order you declared the sources.
Bundler will connect to rubygems.org (and any other sources that you declared), and find a list of all of the required gems that meet the requirements you specified. Because all of the gems in your Gemfile have dependencies of their own (and some of those have their own dependencies), running bundle install on the Gemfile will install quite a few gems.
If any of the needed gems are already installed, Bundler will use them. After installing any needed gems to your system, bundler writes a snapshot of all of the gems and versions that it installed to Gemfile.lock.
When you run bundle install, bundler will (by default), install your gems to your system repository of gems. This means that they will show up in gem list. Additionally, if you are developing a number of applications, you will not need to download and install gems in common for each application. This is nice for development, but somewhat problematic for deployment.
In a deployment scenario, the Unix user you deploy with may not have access to install gems to a system location. Even if the user does (or you use sudo), the user that boots the application may not have access to them.
As a result, bundler comes with a --deployment flag that encapsulates the best practices for using bundler in a deployment environment.
The --deployment flag requires an up-to-date Gemfile.lock to ensure that the testing you have done (in development and staging) actually reflects the code you put into production. You can run bundle check before deploying your application to make sure that your Gemfile.lock is up-to-date. Note that it will always be up-to-date if you have run bundle install, successfully booted your application (or run your tests) since the last time you changed your Gemfile.
I installed mocha using gem install mocha and it did install successfully. There are no version requirements of a specific version in my GEMFILE.
I still get the error :
Could not find mocha-0.10.3 in any of the sources
Anyone knows why ?
To install gems from rubygems.org, you need to set the source :rubygems in the Gemfile, to make it look something like
source :rubygems
gem "mocha"
the problem might also be that your Gemfile.lock requires an older version due to some dependencies, than the one you've installed via gem install mocha, assuming that's what you did.
Showing contents of your Gemfile might help solve this easier though.
Looks like that version of mocha was yanked from RubyGems, so you will need a newer version. If you're not hardlocked to a specific version in your Gemfile, then try a bundle update mocha to update your Gemfile.lock. Otherwise, make sure you're using the spermy operator to specify the version in your Gemfile:
gem "mocha", "~> 0.10.5"