rubyrubygemsnet-http

Is the net/http gem not in the default library for Ruby?


I want to create a Gemfile.lock by typing 'bundle install' but my local machine can't find the gem net/http. I've tried typing 'bundle update net/http' & 'bundle --full-index' & 'gem install bundler' but I keep getting this error when I try 'bundle install' again:

Could not find gem 'net/http' in rubygems repository https://rubygems.org/ or installed locally. The source does not contain any versions of 'net/http'

my Gemfile resembles the following:

source "https://rubygems.org"

gem 'open-uri'
gem 'nokogiri'
gem 'net/http'
gem 'pry'

Other solutions to this problem suggest removing the line for gem net/http because net/http is part of the default library for Ruby...however when I do this everything loads fine, and I can create a Gemfile.lock upon typing 'bundle install' but when I run my code I get the following error:

Traceback (most recent call last): run.rb:4:in `': uninitialized constant Net (NameError) Did you mean? Set

The line of code this refers to is

response = Net::HTTP.get(url)

I'm running Ruby version 2.6.1


Solution

  • The name of the gem is net-http. It is one of the first hits when you google for "net/http".

    However, in Ruby 2.6.1, net/http is still part of the standard library, not a gem. Net/http was only removed from the standard library in Ruby 3.0.