Is there any way to push Ruby gems to own sever? I want to make it publicly accessible (by an outside application). I have tried using geminabox but I have read that geminabox set up a sever to host gem within my organisation. Please suggest.
Thanks in advance.
USING GEMS FROM YOUR SERVER
Use the gem sources command to add the gem server to your system-wide gem sources.
gem sources --add http://localhost:9292
Then install gems as usual:
gem install secretgem
Successfully installed secretgem-0.0.1 1 gem installed
If you’re using Bundler then you can specify this server as a gem source in your Gemfile:
cat Gemfile
source "http://localhost:9292"
gem "secretgem"
bundle
Using secretgem (0.0.1)
Using bundler (1.0.13)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Extracted from RubyGems Guides
You could use geminabox or simpler gem server, just create proxy ( use nginx )
and you could serve your gems world wide, Your customers should set source "your server " in their Gemfile.
Related
I am trying to connect Rails to Sql Server so I need to use an Sql Server adaptor. I installed it by downloading the adaptor locally from github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git. After that I did: gem build activerecord-sqlserver-adapter.gemspec in the directory where I had the spec file, followed by gem install <name of gem that was just built>.
After that, I added this line in the gemfile:
gem 'activerecord-sqlserver-adapter', :path => 'downloads/activerecord-sqlserver-adapter-master\activerecord-sqlserver-adapter-master' , then I ran a bundle install from the project root.
The error is:
Bundler could not find compatible versions for gem "activerecord": In
Gemfile: rails <=4.1.6> x86-mingw32 depends on activerecord <=4.1.6>
x86-mingw32
activerecord-sqlserver-adapter <>=0> x86-mingw32 depends on
activerecord <4.0.0>
What is strange is rails -v doesn't return the rails version although I just installed it.
Instead it throws:
Could not find gem 'tzinfo-data <>=0> x86-mingw32 in the gems available on this machine
Run bundle install to install missing gems
I should specify we are compulsed to use proxies at work
Every few month I keep checking to see if the Sql Server connection is improved/easier to perform with Rails without adaptors and such, because I want to use Sql Server instead of PostgreSQL. No luck so far. Any help is much appreciated. Thanks
It looks like the gem that you are using only supports until rails 4.0.0 (the gemspec forces to be this version).
You might try to use that rails version to see what's going on.
To do so, in your Gemfile.rb you can try this:
gem 'rails', '4.0.0'
gem 'activerecord-sqlserver-adapter', git: 'https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git'
and then run
bundle update rails # to force using the rails version specified in the gemfile
and then run
bundle install
BUT
The gem that you are using has not been updated since 22nd August 2013, so I would not expect it work.
The gem that you are using is a fork of the original project located at https://github.com/rails-sqlserver/activerecord-sqlserver-adapter
If you don't have anything to do with Desarrollo-CeSPI, then you should use the official gem to avoid some problems, for instance that the gem is not maintained anymore.
Can you install your ruby gems via ftp? I mean just copy your local gem directory /var/lib/gems/1.9.1/gems and put it online with filezilla in the ruby>gems>gems directory.
The reason I want to do this is because with cPanel it gives me errors when trying to install some gems (like permission errors, some require ruby >=1.9.2 but I already have ruby 1.9.3). So is there a simple way?
Thanks!
Instead of copying your system's gem which may be ruby version specific, you could place all the required gems sources in your application's lib directory and reference them in your Gemfile. Not that you cannot place these sources in other directories.
Place gem source in your local application e.g. #{Rails.root}/lib/my_gem and update your Gemfile to reference the gem using:
gem "my_gem", path: "lib/my_gem"
Then run bundle install to install the sourced gem in your application.
and you can run
gem server
then add the source
http://some.ip:8808
there you'll have shared the gem installed in that system
As the question states - where does the gem install?
Is it installing within the app directory that I'm working in (i.e. user/sites/sample_app)? Or is it being installed on my computer? If the latter where exactly?
Thanks!
gem install process
first download gem and save desktop
1.next step open command prompt and set location that means c:/desktop> gem install --local "gemname"
2.next step com to rails consoler and type $bundle install --local.
3. type the gem name on gem list
I have two questions:
Where do you install your ruby?
Did you use RVM or rbenv?
Now I will explain your question using my situation as an example.
I use RVM to manage rubies on my mac os.
now the ruby install in path
/Users/pin/.rvm/rubies/ruby-2.1.1
and these will be a gems directory under .rvm path. In this directory,
/Users/pin/.rvm/gems
there are many gems group, I have a group named
ruby-2.1.1#global
which is used by the default ruby version.
This is a directory and there will be a gems directory under it.
/Users/pin/.rvm/gems/ruby-2.1.0/gems
In this directory, you will find all of the gems you installed using cmd
bundle install
If you don't use ruby version management tools like rvm or rbenv, you may find the gems
around your ruby path. If you still can't find them, you can post the details of how you
install the rubies and other system configs, so that we can discuss here.
If you are using rvm then its get installed in
/home/user/.rvm/gems/ruby-version#global/ or /home/user/.rvm/gems/ruby-version/
If you are using specific gemset for gems then
/home/user/.rvm/gems/ruby-version#gemset_name/
If you want to know where gem is installed use gem which *gem_name* e.g.:
gem which rails
If you installed your gems with bundle install use bundle show *gem name* e.g.:
bundle show rails
Gems
If you use gem install x, you're adding the gem to the local ruby version on your system. This is a system-wide installation, and will be stored in your rubylib/ruby/gems dir:
The install command downloads and installs the gem and any necessary
dependencies then builds documentation for the installed gems.
Bundler
Using the bundle install command (when you have a Gemfile & use bundler), you basically tell bundler to install the gems relative to your specific applicaiton:
Bundler makes sure that Ruby can find all of the gems in the Gemfile
(and all of their dependencies). If your app is a Rails 3 app, your
default application already has the code necessary to invoke bundler.
If it is a Rails 2.3 app, please see Setting up Bundler in Rails 2.3.
For example, if you have a Rails 3.2 app, and a Rails 4.1 app on your system, using bundler allows you to instal the dependencies (gems) for each app independently
If you use gem install x, it will install the gem for all applications, and should only be used for things like rmagick and the database connection gems
Generally, if I need a gem, I put it in the Gemfile and bundle install. However, I don't understand if there is a benefit to downloading the gems locally first with gem install _____. Is there any benefit to this? Does bundle install no longer have to connect to the net in that situation?
Bundler installs the gems located in your Gemfile locally the same as if you ran gem install for each of those gems.
Gem install needed for gems that can be used outside of bundler applications. For example request-log-analyzer need to be installed outside of any apps for be available in command line.
I myself use gem install _______ then i use bundle install --local which doesn't require internet connection if the gem is found locally but will return an error if the gem was not found locally...
I find this method faster in downloading and installing gems, plus if the gems are found locally then i have also the benefit of altering the gemfile and install the gems without having internet connection.
If I do gem list rack-cache in rails command prompt then it shows no gem with that name but if I do bundle show rack-cache then it gives me the path like /vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2 of where the gem is stored.
I didn't understood this behavior because if the gem is present in the path with the latter command then why its not showing when I gives gem list rack-cache command.
What's the difference.
The confusion comes from the issue bundler is solving.
When you install Gems into your system-wide gem repository you end up with multiple versions of the gem once you have a couple of apps.
So for example you could end up with 3 Rails versions: 3.2.8, 3.2.6 and 3.1.0
If you do a require rails rubygems could use any of these versions and you'll end up with confusion if your App that was initially built against 3.1.0 isn't compatible with some change s in 3.2.8.
What bundler does is install exactly the gems that are specified in the Gemfile.lock and locks those down for the use of that app. Bundler therefore modifies the load-paths for rubygems so only the Gems in the Gemfile.lock are really available to the app.
Therefore bundle install is not installing gems into the system-wide gem directory but rather installs to a different path for each project. That's why you see the gem in a bundler directory and not system wide.
If you install rack-cache through gem install you'll also see it in gem list.
There is a small difference between bundle show and gem list
bundle show will list all the gems which are installed in your current application[you can see them in Gemfile.lock file],where as gem list will list all the gems installed under any gemset which is set to be using.
bundle show gem_name will give path where it is.
gem list gem_name will give same gem_name with all versions installed into your local gems or gemset.
bundle show :
Shows all gems that are part of the bundle, or the path to a given gem
$ bundle show [GEM] [--paths]
When in development mode on your mac, the gems still get installed in the default gem path, whereas in production mode, they get installed in a folder specific to your project. Try doing a bundle show rails on each machine and you'll see what I mean.
When you run gem list it looks in the main gem folder, and since your production gems are sitting in a project-specific folder, the global gem command doesn't know to look there. So you will need to do a bundle exec to run any of those project-specific gemscommands on the server. For my purposes, I created a be alias to bundle exec. Also, to list your project's gems, you can do bundle list.
See http://gembundler.com/rationale.html#deploying-your-application for the rationale behind this