How to bundle install a git gem behind a proxy? - ruby

I am behind a proxy and I have a git gem in my Gemfile. How can I configure bundler to use git with the appropriate proxy parameters?
I already have $http_proxy appropriatelly set, as well as my .gemrc . Still, it doesn't work.

Are you sure you are using git-over-http? I.e. does your git URL start with http://?

Remember that setting http_proxy for your user wont be preserved when you execute sudo - to preserve it, do:
sudo -E yourcommand
I got my gem install working by first installing cntlm local proxy. The instructions here is succinct : http://www.leg.uct.ac.za/howtos/use-isa-proxies
Instead of student number, you'd put your domain username
To use the cntlm local proxy, exec:
sudo gem install --http-proxy http://localhost:3128 theGem

Related

Error when using overcommit and Github Desktop

I am using overcommit gem (https://github.com/brigade/overcommit) in my project, when I use Github Desktop for osx I get these errors:
This repository contains hooks installed by Overcommit, but the
overcommit gem is not installed. Install it with gem install
overcommit. (1)
The gem is installed, it works in terminal. I guess it's because I use rvm and Github Desktop doesn't know about rvm. Anybody knows how to fix this?
Ok finally got it to work!
Combined the answer from #michelegera with comment from #rewritten
Step 1:
sudo su -
gem install bundler
gem install overcommit
gem install rubocop
Step 2: added command: ['bundle', 'exec', 'rubocop'] to .overcommit.yml
Thanks for the help!
Most likely it's this line where the error occurs. As you can see the main issue is that it's not able to require 'overcommit'. I don't know the GitHub desktop client so well (maybe there is a way to configure it inside of it), but one thing you could do is adding the absolute path where rvm stores your gems to the "require path" in the hook file. This could look like:
$: << "/home/user/.rvm/path/to/gems/dir"
The disadvantage of this is that you would have your absolute path in the hook file and it most likely won't work for others. You might also want to consider installing the gem globally for the the ruby interpreter that executes the script (see Shebang line in the hook file).
You are right, Github Desktop (or any other GUI) isn’t running in your terminal environment, so it knows nothing about your specific RVM installation.
A simple solution is to install overcommit and any other gems required by your hooks into your system Ruby:
sudo su -
gem install bundler
gem install overcommit
gem install rubocop
...
If you installed Git via Homebrew or other means, you might have to change the Git binary used by your GUI.
For example, in Tower, I selected Homebrew’s version rather than the System’s.

Install Ruby gems behind NTLM proxy

I am trying to install ruby gems behind NTLM proxy. My OS is Windows 7. These are all the solutions that I tried, non of them working.
Using HTTP_PROXY:
set HTTP_PROXY=http://domain\user:pass#proxy.company.com:8080
set HTTP_PROXY=http://domain\\user:pass#proxy.company.com:8080
set HTTP_PROXY=http://domain\\user:pass#proxy.company.com:8080/
All above response bad URI
set HTTP_PROXY=http://user:pass#proxy.company.com:8080
Response: bad response Proxy Authentication Required 407
Using -p or --http-proxy parameter from Ruby
gem install -p "http://domain\user:pass#proxy.company.com:8080" rake
gem install -p "http://domain\\user:pass#proxy.company.com:8080" rake
gem install -p http://domain\user:pass#proxy.company.com:8080 rake
gem install -p http://domain\\user:pass#proxy.company.com:8080 rake
gem install --http-proxy "http://domain\user:pass#proxy.company.com:8080" rake
gem install --http-proxy "http://domain\\user:pass#proxy.company.com:8080" rake
gem install --http-proxy http://domain\user:pass#proxy.company.com:8080 rake
gem install --http-proxy http://domain\\user:pass#proxy.company.com:8080 rake
All response: invalid argument
Try all the options above without the domain or encode the \ to %5C will receive reponse: bad response Proxy Authentication Required 407
What did I miss in these command or setup?
You can use cntlm http://cntlm.sourceforge.net/, so that you have a local proxy that requires no authentication (which in turns connects to the ntlm proxy).
Also: How do I update Ruby Gems from behind a Proxy (ISA-NTLM)
Seems like there is no fix for the moment to make work rubygems behind an NTLM proxy: https://github.com/rubygems/rubygems/issues/360.
Anyway, I still found no way to fix it and the only solution is to download a gem (take care of all its dependencies) and install locally (from inside a folder where the gem was saved to):
gem install your_gem_name --local
I have stumbled on a more easier and possibly safer solution that works not just for git but also any command based installers
Rubygems in ruby
npm in node
One solution running all your traffic from command line is proxied with authentiction.
Wont expose your password in the user:password#domain:port format
Solution:
Download Fiddler, It has a built in way to add authentication headers to all requests.
Once running menu Rules-> Automatically Authenticate (Tick that)
Then for git
git config --global http.proxy http://localhost:8888
git config --global https.proxy http://localhost:8888
Thats it!

"Could not find a valid gem in any repository" (rubygame and others)

I've been trying to install this 'rubygame' gem for some time, but whenever I use the command
gem install rubygame
it will give an error:
ERROR: Could not find a valid gem 'rubygame' (>= 0) in any repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ETIMEDOUT: Connection timed out - connect(2) (http://rubygems.org/latest_specs.4.8.gz)
I've also tried other gems but with similar results:
ERROR: Could not find a valid gem 'rake' (>= 0) in any repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ETIMEDOUT: Connection timed out - connect(2) (http://rubygems.org/latest_specs.4.8.gz)
I've already made sure I have an internet connection, and have already tried reinstalling both ruby and rubygems (currently using ruby 1.8, rubygems 1.7.2). Googling didn't help me at all. I would be very grateful if anyone can solve my problem. My sources list only shows http://rubygems.org
Check if you have "https://rubygems.org/" as a source to find gems at:
$ gem sources
*** CURRENT SOURCES ***
https://rubygems.org/
If not, you should be able to add it with
$ gem sources --add https://rubygems.org/
https://rubygems.org/ added to sources
Here are docs for the gem source command.
You can also add the source you want on the command whenever you have troubles using https, like this:
gem install GEMNAME --source http://rubygems.org
It's better to fix the SSL problem though.
are you behind any proxy?
check your browser for proxy that you might use:
execute the command: gem install xxx --http-proxy=http://user:password#server and you should be good to go.
You don't have an Internet connection to rubygems.org.
This happens sometimes if the site is down or blocked.
This command can show you if your connection has a way to reach rubygems.org:
traceroute rubygems.org
Maybe you should try
gem list -r
then
gem install -r rubygame
Also note that with rvmon MacosX (Lion in my case) you should install ruby-1.9.3-p194 (for Xcode 4.x compiler considerations) then
rvm rubygems current
and in my case I had to use
rvm use ruby-1.9.3-p194#global
(which contains bundler, rake, rubygems-bundlerand rvm)
and not
rvm use ruby-1.9.3-p194
(which is empty)
Can you post your versions?
ruby -v
#=> ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]
gem -v
#=> 1.8.19
If your gem command is not current, you can update it like this:
gem update --system
To see if you can connect to rubygems.org using Ruby:
require 'net/http'
require 'uri'
puts Net::HTTP.get URI.parse('https://rubygems.org')
If yes, that's good.
If no, then somehow Ruby is blocked from opening a net connection. Try these and see if any of them work:
curl https://rubygems.org
curl https://rubygems.org --local-port 1080
curl https://rubygems.org --local-port 8080
env | grep -i proxy
If you're using a company machine, or within a company firewall, or running your own firewall, you may need to use a proxy.
For info on Ruby and proxies see
http://www.linux-support.com/cms/http-proxies-and-ruby/
I have fixed this issue using the proxy command option of gem install. It has the following format:
$ gem install --http-proxy http://201.187.107.19:8080 rubygame
Note, the IP address and the port number refers to a proxy. You should search for a proxy list and use one of the proxies there.
This is site with proxies: http://www.cybersyndrome.net/pla5.html
Also, I have to try 7 or 8 different proxies in order to succeed. Do not give up.
Use :
gem sources --add http://rubygems.org/
Do you want to add this insecure source? [yn] [YES]
then use
gem install sass
and done
I know this is a little late, but I was also having this issue a while ago. This is what worked for me:
REALLY_GEM_UPDATE_SYSTEM=1
sudo gem update --system
sudo gem install rails
Hope this helps anyone else having this issue :)
I have tried most of the solutions suggested here but I had no luck.
I found a solution that worked for me, which was manually updating the gemfile to 2.6.7.
The guide on how to do is in guides.rubygems.org: installing-using-update-packages
Download rubygems-update-2.6.7.gem to your C:\
Now, using your Command Prompt:
C:\>gem install --local C:\rubygems-update-2.6.7.gem
C:\>update_rubygems --no-ri --no-rdoc
After this, gem --version should report the new update version (2.6.7).
You can now safely uninstall rubygems-update gem:
C:\>gem uninstall rubygems-update -x
Removing update_rubygems
Successfully uninstalled rubygems-update-2.6.7
The reason why this did not work before was because server used certificates SHA-1, now this was updated to SHA-2.
For what it is worth I came to this page because I had the same problem. I never got anywhere except some IMAP stuff that I don't understand. Then I remembered I had uninstalled privoxy on my ubuntu (because of some weird runtime error that mentioned 127.0.0.1:8118 when I used Daniel Kehoe's Rails template, https://github.com/RailsApps/rails3-application-templates [never discovered what it was]) and I hadn't changed my terminal to the state of no system wide proxy, under network proxy.
I know this may not be on-point but if I wound up here maybe other privoxy users can benefit too.
check your DNS settings ...I was facing similar problem ... when I checked my /etc/resolve.config file ,the name server was missing ... after adding it the problem gets resolved
This worked for me to bypass the proxy definitions:
1) become root
2) gem install -u gem_name gem_name
Hope you can work it out
I tried to install a gem which is for JRuby only, running into the same error. Using jruby's command worked then:
jruby -S gem install some_jruby_gem
If you are running behind the any firewall(if firewall blocking gem installation). just try following command it works.
gem install --http-proxy http://username:pwd#server:port gem
Make sure you type the command from the "App" Directory
It is a permission issue.
try with sudo

"bad response Proxy Authentication" when using gem on Windows

When I try to add source:
C:\>gem source --verbose --add http://gemcutter.org
GET http://gemcutter.org/specs.4.8.gz
407 Proxy Authentication Required
Error fetching http://gemcutter.org:
bad response Proxy Authentication Required 407 (http://gemcutter.org/specs.4.8.gz)
p.s. my Windows XP client accesses the web via a proxy, so I tried:
C:\>gem -v
1.8.10
C:\>gem source --verbose --http-proxy http://192.168.10.24:3128 --add http://gemcutter.org
but returns the same error. How can I fix it?
You need to put the proxy username and password in there somehow.
On *nix machines, gem looks for an environment variable named HTTP_PROXY. You can set this variable on windows too.
Run SET HTTP_PROXY=http://%USER%:%PASSWORD%#192.168.10.24:3128 before you run your gem command.
Another possibility is to install another "proxy" on your computer itself. See How do I update Ruby Gems from behind a Proxy (ISA-NTLM) and http://ntlmaps.sourceforge.net/ for details on this.
You might be able to use rubysspi. See the instructions here.

How to deploy an RubyGem-based Server

We have built a custom socket server in ruby and packaged it as a gem. Since this is an internal project we can not simply publish it to RubyForge or GitHub. I tried to setup our own gem server but gem would not authenticate over https. Our other deployment is all for standard rails applications that use capistrano and svn for deployment.
Our current setup which is to use a rails-like deployment with capistrano. which does the following:
Check out the code from svn
Build the gem
Install the gem
Restart the server
This just seems awkward, and makes the gem packaging seem like extra work -- but outside of the deployment issue it fits really nicely as a gem.
Is there a cleaner approach?
Start
gem server #That will serve all your local installed gems.
gem install YourLocalPkg1.X.X.gem
#on YourHost
use
gem sources --add localhost:8808
gem install YourGem
on client machine
develop something
rake gem
gem install YourLocalPkg2.X.X.gem #on YourHost
use
gem update YourGem #on client machine
Maybe you have a need to use https but I don't see why in your post.
On Some Machine
* Check out the code from svn #the railspart not in the gem
* gem update YourGem # or install if not exist....
* Restart the server
You can install gems from the local filesystem.
gem install /path/to/some.gem
Shouldn't be too hard for you to script scp with that, or use an NFS mount, etc.
gem install --local path_to_gem/filename.gem will help. Or you can get a trusted certificate on your web server.
You might be able to install from the server with gem install -P NoSecurity or -P LowSecurity, but I haven't tried that.
http://www.rubygems.org/read/chapter/21

Resources