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

2

7

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?

Puffball answered 16/3, 2016 at 17:26 Comment(1)
I had the same problem.. Some one knows how to fix it?Ocher
U
9

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
Upwards answered 11/7, 2016 at 12:42 Comment(4)
This worked for me. Should just have to copy the .gemrc file to the location above and then your connection should be fine.Triacid
On windows 10 my .gemrc file was in /c/users/<username>Katelin
Solved! Thanks too much.Gussiegussman
The issue is not really solved. gem sources ---add works for all https sources, but not for HTTP sources. when we add HTTP source, it asks for yn. How do we remove it?Bubaline
S
0

The force option will bypass the yes/no prompt

gem sources -f --add http://rubygems.org
Shipment answered 18/7, 2023 at 15:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.