24

I have Ruby installed, but I still need to add it to the PATH variable. I found something online for how to manually add it using the command line:

set PATH=C:\Ruby200-x64\bin;%PATH%

But before I try it, I want to be sure it's not going to overwrite what's currently in the PATH variable. (I have no experience with this stuff so I don't know what to expect).

Thanks in advance for your help!

glucas
  • 442
  • 3
  • 10
kburlz
  • 606
  • 1
  • 4
  • 18

7 Answers7

29

first, notice that this question is not really about Ruby, rather about how to set a path in windows (it work the same way if you want to add an executable different from Ruby)

second, you are not overwriting the PATH environment variable because you add the existing content of the same to the new one you are setting in:

set PATH=C:\Ruby200-x64\bin;%PATH%

the %PATH% is the current content of the PATH variable.

Consider using

 set PATH=%PATH%;C:\Ruby200-x64\bin

instead, this will make your OS search the original path before searching the ruby bin folder. Maybe it makes few difference on modern computers, but my old DOS days claim the second solution is better.

third and last point, in Windows you can set environment variables in control panel / system properties How to get there depends on the version of your OS, but if you search for the ambient variables and system variables you should get there.

Chosmos
  • 596
  • 9
  • 11
  • 2
    In Windows 10, the path variables can ve edited by typing "variables" in the search box, then clicking "Edit enviroment variables". It's necesary to leave a trailing dash, ex.: C:\Ruby200-x64\bin\ (notice the last character is a dash) – Fran Cano Aug 03 '16 at 22:59
7
  1. From the Desktop, right-click the very bottom left corner of the screen to get the Task Menu.
  2. From the Task Menu, click System.
  3. Click the Advanced System Settings link in the left column.
  4. In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
  5. In the Environment Variables window (pictured below), highlight the Path variable in the "System variables" section and click the Edit button.
  6. Add or modify the path lines with the paths you want the computer to access. For ruby it will be:

    ;YOUR_RUBY_INSTALLATION_PATH\bin;
    

The operation with set PATH=C:\Ruby200-x64\bin;%PATH% is probably only temporary until you restart your computer.

Kamil Lelonek
  • 14,592
  • 14
  • 66
  • 90
4

I just wanted to let everyone know that when you install rubyinstaller on Windows and follow its steps, there is no option to 'add to path variables' because it automatically adds it.

Rubyinstaller trolled me hard because it said gem not found when I did gem install sass immediately after install.

Your path variable is probably already set if you used rubyinstaller.

The trick is to open CMD or I would imagine, PowerShell, ConEMU, etc, git bash, and type gem.

  1. Press WINKEY and type cmd
  2. Type gem install sass (or whatever else that is in the bin folder for Ruby)

I just went to add the PATH variable, and it was already set, so my problem was the garbage command line tool that opened after installing rubyinstaller.

You can also do these steps to add to the PATH variables:

  1. Press WINKEY
  2. Type view advanced system settings
  3. Open that
  4. Click Environment Variables
  5. Click Path in the list
  6. Click Edit
  7. Check if C:\Ruby24-x64\bin is already there, if so, done
  8. Click New and type in C:\Ruby24-x64\bin
  9. Done
Community
  • 1
  • 1
agm1984
  • 15,500
  • 6
  • 89
  • 113
  • If it is already in the path, why doesn't the gem command work? – Scott M. Stolz Jul 14 '20 at 06:50
  • I figured out why it would not run. If you run gem in the Windows Power Shell, it does not work, but if you run the same exact command at the Command Prompt, it works. – Scott M. Stolz Jul 14 '20 at 10:53
  • I think it has to do with updating the terminal. For example, the path variable is set but the terminal isn't using the updated paths yet. – agm1984 Feb 04 '21 at 22:11
1

Yes, this is correct. In your example %PATH% will be expanded to the current value of the PATH variable, so this command is effectively adding a new entry to the beginning of the PATH.

Note that calling set PATH will only affect the current shell. If you want to make this change permanent for all shells, the simplest option is to set it as a user variable using the Environment Variables dialog box.

On Windows 8 you can open this dialog by hitting Win+s and searching for 'environment variables'. On earlier versions of Windows you can right-click 'My Computer', choose Properties, then Advanced system settings, then Environment variables. You can create (or update) a PATH variable in the user variables section and add whatever entries you need. These will be appended to the existing system path. If you take this approach you will need to open a new cmd shell after updating the variables.

glucas
  • 442
  • 3
  • 10
0

Fear nothing, What you are doing is prepend C:\Ruby200-x64\bin to the existing %PATH%, this is what the command you posted does.

The path is a list of directories, separated by ;, in which the system will look for the command you execute.

In your case it's:

  1. C:\Ruby200-x64\bin
  2. %PATH%, if you print it on the command line, you'll find it's itself a list of directories separated by ;.

In case you want to make your change permanent, you have to change your PATH sytemwide.

Nabil Kadimi
  • 10,078
  • 2
  • 51
  • 58
0

For CLI, as noted elsewhere calling SET on the path variable only acts on the current window and closing it or restarting windows voids the change.

Example the transient Version selected as the answer:

set "PATH=%PATH%;C:\Ruby200-x64\bin"

To correctly set the path permanently in CLI use the path command:

PATH %PATH%;C:\Ruby200-x64\bin

This will persist between CMD windows and after reboots.

Ben Personick
  • 3,074
  • 1
  • 22
  • 29
0

I know this is questions has the Windows tag, however it is one of the first DuckDuckGo results for "ruby gems add to path" so I just wanted to add this.

On Linux you can add this line to the end of your .bashrc in order to add it to your path:

export PATH=$PATH:~/.gem/ruby/2.6.0/bin

CorruptComputer
  • 328
  • 3
  • 16