Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 8

Can't install Ruby gem after publishing to Github Package Registry

Solved! Go to Solution.

I'm using the standard template (https://github.com/actions/starter-workflows/blob/master/ci/gem-push.yml) for publishing a Ruby gem to the package registry. I commented out the part of publishing to RubyGems, since this gem is private for now. After successfully publishing the gem, I am unable to install it locally. The error I'm getting is a 401 after copying the install command from the packages page.

 

 

gem install my_gem --version "0.1.0" --source "https://rubygems.pkg.github.com/jer-k"
ERROR:  Could not find a valid gem 'my_gem' (= 0.1.0), here is why:
          Unable to download data from https://rubygems.pkg.github.com/jer-k/ - bad response Unauthorized 401 (https://rubygems.pkg.github.com/jer-k/specs.4.8.gz)

 

 

Some notes:

The repository 'my_gem' is a private repo I mantain. 

The OWNER environment variable in the action is jer-k

The GPR_AUTH_TOKEN environment variable has package:write package:read repo permissions.

I added the same token to my .gem/credentials following the instructions from https://help.github.com/en/articles/configuring-rubygems-for-use-with-github-package-registry#authen...

 

I'm must be missing something about how to authenticate. I was also trying to search how to distinguish between publishing public and private packages (this is a feature the package registry talks about) but I couldn't find anything to indicate how to do it; maybe that is based on whether or not the repository is private?

 

 

7 Replies
GitHub Staff
Message 2 of 8

Re: Can't install Ruby gem after publishing to Github Package Registry

Sorry to hear that.  Just to clarify a few things:  you're using the same GPR_AUTH_TOKEN that you set up as a secret in your Actions workflow?  When you created the file, did you use a text editor?  Are you on Windows?  (That may change the line endings).

 

If you open bash (Git Bash if you're on Windows) and run:

 

printf -- "---\n:github: Bearer ${GPR_AUTH_TOKEN}\n" > $HOME/.gem/credentials

Is there any change in behavior?

Copilot Lvl 3
Message 3 of 8

Re: Can't install Ruby gem after publishing to Github Package Registry

Yes, I'm using the same token in the action and the command line. I'm on OSX and I had set it up through vim originally. I just used that command and the result was the same.

Copilot Lvl 2
Message 4 of 8

Re: Can't install Ruby gem after publishing to Github Package Registry

Having the same issue (Linux).

 

~/.gem/credentials is configured properly.

 

The same token works with bundler on the same machine, but `gem install xyz --source <github>` fails with `Unauthorized 401 (https://rubygems.pkg.github.com/ruby-next/specs.4.8.gz)`.

 

Copilot Lvl 2
Message 5 of 8

Re: Can't install Ruby gem after publishing to Github Package Registry

Also having the same issue, but only for some gems. Bundle install / update simply refuses to find a gem which is clearly published to Github Packages. Downloading the binary of the gem into vendor cache resolves the issue, but that is definitely a suboptimal solution. We've transitioned from Gemfury to Github Packages, and I've seen had an issue like this occur on Gemfury. Very confusing.

Copilot Lvl 2
Message 6 of 8

Re: Can't install Ruby gem after publishing to Github Package Registry

We've given up on Github Packages now and gone back to Gemfury. I think this one needs a bit more baking before it's ready. We're super keen to come back and use it once it's done.

Solution
Ground Controller Lvl 1
Message 7 of 8

Re: Can't install Ruby gem after publishing to Github Package Registry

I believe I had the same issue as the original post, in that the command line given by github to install the gem gave that error.  As far as I can tell, gem install does not use the credentials file.  But the command worked when I changed the github URL to include user name and token, as per basic authentication.

 

--source "https://{username}:{token}@rubygems.pkg.github.com/..."

Copilot Lvl 3
Message 8 of 8

Re: Can't install Ruby gem after publishing to Github Package Registry

Finally circled back to this and I'm accepting this as the solution. It is not optimal, but it works for now!

 

Also just don't forget to remove the `{}` around the input of your username and token. Was blankly staring at a non descriptive error like 'why isn't this working' for 5 minutes...