How do I add Ruby to the PATH variable on Windows?
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.
- From the Desktop, right-click the very bottom left corner of the screen to get the Task Menu.
- From the Task Menu, click System.
- Click the Advanced System Settings link in the left column.
- In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
- In the Environment Variables window (pictured below), highlight the Path variable in the "System variables" section and click the Edit button.
-
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.
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
.
- Press WINKEY and type
cmd
- 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:
- Press WINKEY
- Type
view advanced system settings
- Open that
- Click
Environment Variables
- Click
Path
in the list - Click
Edit
- Check if
C:\Ruby24-x64\bin
is already there, if so, done - Click
New
and type inC:\Ruby24-x64\bin
- Done