Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add Ruby to the PATH variable on Windows?

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!

like image 443
kburlz Avatar asked Nov 15 '14 15:11

kburlz


4 Answers

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.

like image 155
Chosmos Avatar answered Sep 22 '22 17:09

Chosmos


  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.

like image 40
Kamil Lelonek Avatar answered Sep 24 '22 17:09

Kamil Lelonek


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
like image 38
agm1984 Avatar answered Sep 22 '22 17:09

agm1984


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.

like image 30
glucas Avatar answered Sep 25 '22 17:09

glucas