I've installed a gem from command line:
sudo gem install jalalidate
gem says it's installed:
$ gem list jalalidate
*** LOCAL GEMS ***
jalalidate (0.3.2)
And it can be loaded:
ruby -rubygems -e 'require "jalalidate"' # output is empty, (success?)
Though when I try to include this gem in a Rakefile, rake fails:
# Rakefile:
require "rubygems"
require "bundler/setup"
require "stringex"
require "jalalidate"
# Terminal:
$ rake new_post["title"]
rake aborted!
cannot load such file -- jalalidate
(See full trace by running task with --trace)
Note:
I'm using octopress blogging system, and I'm trying to convert dates generated by Time.now.strftime('%Y-%m-%d %H:%M') to Jalali calender system, (JalaliDate.new(Date.today).strftime('%Y-%m-%d')).
I'm not familiar with Ruby
Update:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /var/lib/gems/1.9.1
- /home/soroush/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Your Rakefile has require "bundler/setup" before you try to require jalalidate which means you are using Bundler and so you have a Gemfile, which is restricting the gems (and versions) available.
In order to use the gem in your project, add the line
gem "jalalidate"
to the Gemfile.
See this question about why using sudo with gem commands is mostly a bad idea.
I recommend trying to install the gem without sudo: gem install jalalidate
Related
I am a new bee with sinatra and i am not an expert with ruby management tools like rvm and rbenv and i have the following issue: When i run a bundle install in my app, gems are installed and i have the following response "Bundled gems are installed into ./vendor/bundle." But when i try to run my sinatra app, it is displayed that i dont have sinatra installed and when i try this command line "gem list", i dont it found too.
I am using rbenv, and i dont have a clue how to resolve that. When i install gem by gem like "gem install sinatra" it works fine, but it's really painful, so my question is how to resolve that ?
PS: i tried to manage my ruby manager with rvm but i had issues so i moved to rbenv, maybe this is all about the path where gems are installed
This is a print of my gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 2.5.1
- RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-darwin15]
- INSTALLATION DIRECTORY: /Users/laadhari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- USER INSTALLATION DIRECTORY: /Users/laadhari/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /Users/laadhari/.rbenv/versions/2.3.1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/laadhari/.rbenv/versions/2.3.1/bin
- SPEC CACHE DIRECTORY: /Users/laadhari/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/laadhari/.rbenv/versions/2.3.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-15
- GEM PATHS:
- /Users/laadhari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- /Users/laadhari/.gem/ruby/2.3.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/laadhari/.rbenv/versions/2.3.1/bin
- /usr/local/Cellar/rbenv/1.0.0/libexec
- /Users/laadhari/.rbenv/shims
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
A print of my Gemfile
source 'https://rubygems.org'
gem 'sinatra', '~> 1.4.7'
gem "sinatra-activerecord"
gem 'mysql2'
gem 'rest-client'
gem 'thin'
gem 'rake'
when i run :
gem list
*** LOCAL GEMS ***
...
After successfully running bundle install, I dont find gems from Gemfile in the local gems...
One of the objectives of Bundler is to not pollute the global Gem list. This is achieved by NOT installing the bundled gems to the default location.
So to make sure your app finds the bundled gems, you have a few options:
Using bundle exec
When starting your application (ie. using rackup or ruby ./app.rb), prefix the command with bundle exec
bundle exec rackup
#=> Thin web server (v1.7.0 codename Dunder Mifflin)
#=> Maximum connections set to 1024
#=> Listening on localhost:9292, CTRL+C to stop
#=> ...
More Info: https://bundler.io/v1.12/man/bundle-exec.1.html
Using Bundler.setup
Before loading your dependencies (with require), load Bunder:
require 'rubygems'
require 'bundler/setup'
# require your gems as usual
require 'sinatra'
More info: https://bundler.io/v1.12/bundler_setup.html
Source & Further reading
I strongly suggest to read the excellent documentation at https://bundler.io/v1.12/#getting-started .
One more thing, to find out WHERE your bundled gems actually are installed, run the following command:
bundle config path
#=> Settings for `path` in order of priority. The top value will be used
#=> Set for your local app (/path/to/project/.bundle/config): ".bundle"
I have installed the rubygems-mirror gem (successfully it would seem), but when I execute the gem I get the following error:
$ gem mirror
ERROR: Install the rubygems-mirror gem for the mirror command
EDIT: The installation was done using a gem install command, and I have setup the ~/.gem/.mirrorrc file as a cut/paste from the gem documentation, save the target directory.
Both doing an listing of ~/.gems/ruby/gems and running gem list show I have rubygems-mirror version 1.1.0 on my system. Here is my gem list:
$ gem list rubygems-mirror
*** LOCAL GEMS ***
rubygems-mirror (1.1.0)
$ ls ~/.gem/ruby/gems/rubygems-mirror-1.1.0
CHANGELOG.rdoc lib Manifest.txt Rakefile README.rdoc test
And here is my gem environment:
$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.14
- RUBY VERSION: 2.0.0 (2014-11-13 patchlevel 598) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/localadm/.gem/ruby
- RUBY EXECUTABLE: /usr/bin/ruby
- EXECUTABLE DIRECTORY: /home/localadm/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/localadm/.gem/ruby
- /usr/share/gems
- /usr/local/share/gems
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
I've never had such an issue with a gem before, I'm a little confused at what to do here. To make things even more confusing, I can run gem mirror --help and receive the correct help text for the mirror gem as output.
UPDATE: It seems I am able to use a work-around. I have cloned the git source repo, and seem to be able to execute $ rake mirror:update successfully. I'm sitting at about 2000/819236 gems downloaded, but so far so good.
Still would like to figure out how I can run the mirror simply with $ gem mirror as it should work.
I searched through similar questions, but still could not solve this problem. I installed my jiveapps gem, but then it cannot be found.
Successfully installed jiveapps-1.0.7
1 gem installed
Installing ri documentation for jiveapps-1.0.7...
Installing RDoc documentation for jiveapps-1.0.7...
new-host-2:sites jeffreyerickatz$ gem list jiveapps
*** LOCAL GEMS ***
The following also did not work:
new-host-2:sites jeffreyerickatz$ gem which jiveapps
ERROR: Can't find ruby library file or shared library jiveapps
new-host-2:sites jeffreyerickatz$ rake gemspec
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
(See full trace by running task with --trace)
You can see that I only have one version of ruby installed
ew-host-2:sites jeffreyerickatz$ rvm list
rvm rubies
=* ruby-1.9.3-p194 [ x86_64 ]
# => - current
# =* - current && default
# * - default
and here are my gem paths
- GEM PATHS:
- /Users/jeffreyerickatz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1
- /Users/jeffreyerickatz/.gem/ruby/1.9.1
and when I do sudo gem environment I get
sudo gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-darwin11.4.2]
- INSTALLATION DIRECTORY: /Users/jeffreyerickatz/.rvm/rubies/ruby-1.9.3- p194/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /Users/jeffreyerickatz/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
- EXECUTABLE DIRECTORY: /Users/jeffreyerickatz/.rvm/rubies/ruby-1.9.3-p194/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
- GEM PATHS:
- /Users/jeffreyerickatz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1
- /Users/jeffreyerickatz/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
gem path
new-host-2:Desktop jeffreyerickatz$ echo $GEM_HOME
/Users/jeffreyerickatz/.rvm/gems/ruby-1.9.3-p194
If you copied pasted that correctly, it looks like gems are being installed into "/Users/jeffreyerickatz/.rvm/rubies/ruby-1.9.3- p194/lib/ruby/gems/1.9.1" (note the space between 1.9.3- and p194).
You can further check by echo $GEM_HOME. $GEM_HOME should be set to your gem path.
I am trying to run a Rails app on my Snow Leopard Mac. I never worked with Ruby or Rails before, so any hint is welcome.
In terminal I went to the folder of the app, and ran rails server
and received the following error:
Could not find gem 'mysql2 (>= 0) ruby' in any of the gem sources
listed in your Gemfile. Run `bundle install` to install missing gems.
My gemfile looks like:
source 'http://rubygems.org'
gem 'rails', '3.1.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development do
gem 'mysql2'
end
group :production do
gem 'pg'
gem 'thin'
end
and database.yml has adapter: mysql2 for all environments. I already ran bundle install, and from running gem list I got:
mysql2 (0.3.11)
My gem environment is:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.17
- RUBY VERSION: 1.9.3 (2012-02-16 patchlevel 125) [x86_64-darwin10.8.0]
- INSTALLATION DIRECTORY: /Users/user/.rvm/gems/ruby-1.9.3-p125#rails3
- RUBY EXECUTABLE: /Users/user/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
- EXECUTABLE DIRECTORY: /Users/user/.rvm/gems/ruby-1.9.3-p125#rails3/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-10
- GEM PATHS:
- /Users/user/.rvm/gems/ruby-1.9.3-p125#rails3
- /Users/user/.rvm/gems/ruby-1.9.3-p125#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
I have been going around with this for more than last two hours with no luck so far.
I installed slim gem to a custom directory of my own but require 'slim' gives me error.
Installing slim:
$ cd /var/www
$ mkdir project
$ cd project/
$ gem install slim -i gems/
Fetching: temple-0.4.0.gem (100%)
Fetching: slim-1.2.2.gem (100%)
Successfully installed temple-0.4.0
Successfully installed slim-1.2.2
2 gems installed
Installing ri documentation for temple-0.4.0...
Installing ri documentation for slim-1.2.2...
Installing RDoc documentation for temple-0.4.0...
Installing RDoc documentation for slim-1.2.2...
$ ls gems/
bin/ doc/ specifications/
cache/ gems/
$ ls gems/gems/
slim-1.2.2 temple-0.4.0
$ ls gems/gems/slim-1.2.2/
benchmarks CHANGES lib Rakefile slim.gemspec
bin Gemfile LICENSE README.md test
$ ls gems/gems/slim-1.2.2/lib/
slim slim.rb
Gem Environment (If you notice I added /var/www/project/gems to GEM_PATH):
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.9.1
- /home/john/.gem/ruby/1.9.1
- /var/www/project/gems
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gempath" => ["/usr/local/lib/ruby/gems/1.9.1", "/home/john/.gem/ruby/1.9.1", "/var/www/project/gems"]
- REMOTE SOURCES:
- http://rubygems.org/
Testing:
$ irb
irb(main):001:0> require 'slim'
LoadError: no such file to load -- slim
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from (irb):1
from /usr/local/bin/irb:12:in `<main>'
Any idea what's wrong ? I added /var/www/project/gems in the GEM_PATH yet require 'slim' won't load the gem, why so ? Is this a bug with rubygems ?
Same problem when i write require 'slim' in /var/www/project/index.rb and ruby index.rb.
I would heartily recommend using bundler, which will not only manage this but also version pinning and deployment on your behalf.
The relevant invocation would be; in Gemfile
source :rubygems
gem "slim"
And then
gem install bundler && bundle install && bundle exec irb
At which point require 'slim' will work.
Since you're installing slim at /var/www/project/gems/ you'll have to add it to the load path or require it by full path:
require '/var/www/project/gems/slim'
or add it to your load path:
$LOAD_PATH.unshift(File.dirname('/var/www/project/gems/'))