How to install ruby gem packages without Internet?

git_stats is a good tool to analyze the statistics of a git repo, there is an issue tomgi/git_stats#45 How to Install Offline in that project, I think this is a good question, sometimes the speed or quality of Internet is not so fast and stable, or we want to install a gem package on a server that can only access internal network only, so I tried to figure it out, that’s the solution:

Milly/gem-fetch-dependencies is a ruby script posted on gist, it can help us fetch gem packages with the dependency, we can’t just fetch the package we want to use via gem fetch , because it doesn’t handle the dependency issue, that’s why we need this script, download the script(raw) first:

and we can easily fetch the gem packages with dependencies with this script like this:
$ ruby gem-fetch-dependencies fetch --dependencies

Once we fetched all the packages, you copy them to everywhere you want, and install them locally:
$ gem install -f --local *.gem