gem, RubyGems, is a package manager for Ruby. It seems that it is not installed on your computer, or not available inside your $PATH.
First, try to execute which gem to see whether you can access it or not. Then,
If you previously installed
gem, you probably have to modify$PATHto add the package manager's executable location.If you did not, you need to. On Windows, your best option is to install Cygwin.
To setup you Ruby development environment on Windows:
Install Ruby via RubyInstaller: http://rubyinstaller.org/downloads/
Check your ruby version: Start - Run - type in
cmdto open a windows consoleType in
ruby -vYou will get something like that:
ruby 2.0.0p353 (2013-11-22) [i386-mingw32]
For Ruby 2.4 or later, run the extra installation at the end to install the DevelopmentKit. If you forgot to do that, run ridk install in your windows console to install it.
For earlier versions:
- Download and install DevelopmentKit from the same download page as Ruby Installer. Choose an ?exe file corresponding to your environment (32 bits or 64 bits and working with your version of Ruby).
- Follow the installation instructions for DevelopmentKit described at: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit#installation-instructions. Adapt it for Windows.
- After installing DevelopmentKit you can install all needed gems by just running from the command prompt (windows console or terminal):
gem install {gem name}. For example, to install rails, just rungem install rails.
I recommend you just use rubyinstaller
It is recommended by the official Ruby page - see https://www.ruby-lang.org/en/downloads/
Ways of Installing Ruby
We have several tools on each major platform to install Ruby:
- On Linux/UNIX, you can use the package management system of your distribution or third-party tools (rbenv and RVM).
- On OS X machines, you can use third-party tools (rbenv and RVM).
- On Windows machines, you can use RubyInstaller.
Most of the Ruby gems are developed for Unix and require some extra tools to make it work on Windows.
In order to install those gem in Windows, you need Ruby DEVELOPMENT KIT from the download link (choose the correct installer based on your Ruby version).
Extract the installation to some permanent location. In my system, it is C:\RubyDevKit.
Open command prompt and cd to the extracted location and execute the following commands
cd C:\RubyDevKit
ruby dk.rb init
ruby dk.rb install
devkitvars.bat
The last command is what I missed initially and took sometime to figure out. Now try installing your gem; it worked for me.
Additional Information
The Ruby Development Kit has a component called MinGW which is used to run Unix command on Windows.
The below error, in my case, was Ruby Development Kit not added to the system path variable
make 'make' is not recognized as an internal or external command, operable program or batch file.
The command devkitvars.bat adds the Development Kit to the system path.
Ruby installation wizard asks you "Add Ruby executables to your PATH", for me, easy solution is to uninstall ruby and install again, this time checking the check box "Add Ruby executables to your PATH"

It seems a unexpected result of cygwin 2.5.2 release
https://www.cygwin.com/ml/cygwin/2016-06/msg00378.html
As workaround, downgrade cygwin package to 2.5.1
A way to fix this without changing the rvm build process is:
ln -s /cygdrive/c/Windows/System32/kernel32.dll /usr/lib/kernel32
This happens because ruby is looking for a shared library named simply kernel32. Cygwin 2.5.1 and earlier automatically added the ".dll" extension to shared library loads. But cygwin 2.5.2 introduced a patch requiring full shared library filenames. Adding a symbolic link within the library search path (/usr/lib) allows the library to be found even when loaded with the old-style name.
You have two different versions of Ruby installed. First is in:
/usr/bin/ruby
and second one is in:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
The problem is that one is used in command line (i.e. to install gems) and another is used by web server to run Rails.
Since your web server is using second Ruby version one solution would be to install gem using that Ruby version. Alternatively, you can tell your web server to use different Ruby version - depending on which server you are using this can be achieved in different ways.
Just try
sudo update-alternatives --config ruby
and select the other ruby version. Worked for me.