Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically add http://rubygems.org as a gem source?

Tags:

rubygems

The corporate proxy at my company seems to be interfering with https connections to rubygems.org (but not http connections), causing failures when I attempt to install gems from the default gem source, https://rubygems.org. For this reason, I'm attempting to update my gem sources to replace the default source with the unsecured http version of rubygems.org. (And yes, I'm aware of the security implications of this.)

When I do this manually from the command line everything works fine; I just have to get past a warning message:

$ gem sources --add http://rubygems.org
https://rubygems.org is recommended for security over http://rubygems.org

Do you want to add this insecure source? [yn]

However, there doesn't seem to be a way to bypass this prompt when running this command from an automated script. The gem command doesn't have a --yes or --force option (as far as I'm aware), and attempting to use the yes utility to get past the prompt just results in the following error message:

$ yes | gem sources --add http://rubygems.org
ERROR:  While executing gem ... (Gem::OperationNotSupportedError)
    Not connected to a tty and no default specified

How can I get through the warning message to programmatically add http://rubygems.org as a source?

like image 282
Ajedi32 Avatar asked Mar 16 '16 17:03

Ajedi32


People also ask

How do I push a gem to RubyGems?

From the main menu, select Tools | Gem | Push Gem. In the Run tool window, specify your RubyGems credentials. Your gem will be published to RubyGems.org.

Which of the following commands will be verify the existence of the RubyGems in your system?

Use $ gem list | grep YOURGEM to check if the YOURGEM is present.

How do I get RubyGems?

Open up the 'Software Center' app from your launcher and type in `RubyGems` without quotes into the application search box at the top right, and press [enter]. RubyGems then can be installed by just clicking on the button labeled 'Install', thats it.

What is RubyGems in Ruby programming language?

RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a "gem"), a tool designed to easily manage the installation of gems, and a server for distributing them.


1 Answers

To remove the https sources:

gem sources -r https://rubygems.org/

If you put the following in ~/.gemrc it will pick it up in gem env

---
:backtrace: false
:bulk_threshold: 1000
:sources: ["http://rubygems.org"]
:update_sources: true
:verbose: true

gem env snippet:

 - GEM CONFIGURATION:
    - :update_sources => true
    - :verbose => true
    - :backtrace => false
    - :bulk_threshold => 1000
    - :sources => ["http://rubygems.org"]
 - REMOTE SOURCES:
    - http://rubygems.org
like image 88
Domhnaill Byrne Avatar answered Sep 29 '22 07:09

Domhnaill Byrne