Run Ruby program and compile sources using Notepad++

Notepad++ is for sure one of the most popular text editing software of the present and in this post I will show you how you can use it to run Ruby program and compile sources. It is preferred by most of the programmers and software & web developers due to an extended use over different platforms and its capability to offer features like syntax highlighting for most programming languages. It can also be configured to run external tools such as Java, Ruby or C++ source files.

This piece of software is an open-source software meaning it is free, but this won’t be the only thing that this program has to offer. It has many options that you have to experience sooner or later and you won’t be disappointed.

To make Notepad++ work with different software, compile different source codes with it, you will have to manipulate its built-in environment variables. But first let’s talk a bit about Ruby, which is the main focus of this article, to be more specific the possibility to compile Ruby source files with the help of Notepad++.

If you need full features of an IDE, such as debugging for Ruby then you are probably using one of the following Integrated Development Environments: Eclipse, Aptana Studio, NetBeans 6.9.1 and earlier versions, RubyMine from JetBrains, Redcar or IntelliJ IDEA.

However, if you are writing small Ruby programs and you don’t need such features, one of the best options would be to use the light weight code editor Notepad++.

If you don’t have it installed yet, you can find it by clicking the link in the first sentence of this article and then find the download section. At this moment, the latest version can be found here: http://notepad-plus-plus.org/download/v6.2.html

If you already have it installed, I would recommend at least a reinstallation over your current one (the uninstall of the previous version is not required) with the sole remark that you should install it using below settings to get a faster approach of having the same settings to a new computer, in case there will be such a need for change. This will avoid any complications and might save you some time and optimize any future change of your computer.

Just download the latest version or use the current installer you already have (the same version you already have, if you kept the installer), use next to confirm each window until you reach this one, which should be by default similar to below window. If not, change the settings accordingly.

The next window is what actually matters. While all the other components are optional and you can check them depending on your needs, I recommend checking the first option as you can see below, for the same argument stated before which says that if you need to change your computer you only have to copy the installed folder to the new machine in order to have all the customization made to the Notepad++ installation to the new computer too. The basic idea is to click on “Don’t use %APPDATA%” to have it checked.

Then complete the process with install, next and finish or close, depending on which of these options will follow.

Regarding installation, it is as simple as any installation, with a little remark that you should follow the steps until you reach the window below where you should click to select the first two options: “Install Tcl/Tk support” and “Add Ruby executables to your PATH”.

The first option, Tcl/Tk support will allow you to create GUI applications in Ruby.

The second option that says it will add Ruby executables to your PATH does exactly what it says: it will add a path to your system PATH variable so that you can use Ruby interpreter and programs from any command window.

Note: If you already have Ruby installed and you don’t have the value added to PATH for it, you should either add it manually using below instructions or reinstall the Ruby installer using above options.

Regarding the Ruby installation, in order to complete, you have to click install and then finish button and the process of installation is complete.

Run Ruby program – Manually add Ruby location to System Environment PATH

To manually add the Ruby location to system PATH, go to Start – Run – type “sysdm.cpl” without the quotes. Navigate to Advanced in the tabs and then go to “Environment Variables” button. At system variables, in the bottom section of the window, find PATH variable, select it and click edit.

For me, as you can see above it is already added but for you, if you don’t have it, you will have to add the same thing, assuming you have used the default folder for installation. Else, locate the path to the bin folder inside the installation directory and add it instead of mine.

Run Ruby program – Configure Notepad++ for editing Ruby programs

Under “Available Items” you will see supported programming languages. You should also know you can disable the syntax highlight for different programming languages from here by adding them to the “Disabled Items” column/list ( alternate solution to disabling languages is to edit langs.model.xml and stylers.model.xml and comment any lines that make references to the programming language you are trying to remove highlight for ).

To continue with our guide, under the ”Tab Settings” for Default modify the tab size to 2 by clicking it and typing in the new value and confirming with enter. Also, click the checkbox “Replace by space”, you should have it “enabled” so that you can use spaces instead of tab character.

Next step is to add a custom menu in the Run menu of Notepad++ for the Ruby programs so that you can actually run Ruby programs directly from the text editor.

From the Notepad++ menu click Run – Run which opens up the following window:

In the above text field write the following command:

cmd /K ruby “$(FULL_CURRENT_PATH)”

Note: You don’t have to replace FULL_CURRENT_PATH, just copy/paste the dull command as above written. It will be automatically read from System Environment PATH.

In order for this to work you should have Ruby 1.9.x installed and the Ruby bin location added to PATH in system environment.

When you have the command typed in, click on save button and the following window will appear:

Now you have to select any key you wish to use in order to run Ruby programs from the pick list. Due to historical events for me, I am used to F5 as you can see above, but you can pick anything including a combination of keys like CTRL, ALT, SHIFT (you have to check them) and something.

Enter a name for the shortcut in the “Name” field, for example “Execute Ruby Program ” and then confirm with OK.

If you click now Run from the Notepad++ menu, you will see your newly created shortcut to be something like this:

Before you can actually use this shortcut you will have to save the program as a ruby file to have an actual location, a store location. In other words, if you don’t have a physical file with .rb extension, when you use your shortcut, you will just get an error saying something like “there is no such file or directory (LoadError)”.

To bypass this, after you write your code save it to a file with a name and then use the shortcut. You can see an example below to test it if it is working or not.

As you can see, I created a file called test.rb and written down inside it below text as being the code to a simple program. Then I pressed F5 on my keyboard and confirmed the command to run (the code we used to add to create the shortcut in first place):

Puts “Hello World!”

This will return a command window as in the next image:

Hope this helps any of you reading it and do tell me if you would like to know some other things regarding how to run Ruby program, maybe another example or problems you’ve encountered. I will also try to add more details as there are a few more tweaks you can do in Windows to optimize the work with Ruby.

VN:F [1.9.22_1171]

please wait...

Rating: 4.6/5 (12 votes cast)

Run Ruby program and compile sources using Notepad++, 4.6 out of 5 based on 12 ratings

About The Author

28 Comments

Hi ,
I’ve tried the steps, up until the location of the PATH as mentioned above, but i’m stucked at the point of setting the second argument values after the semi-colon’;’ symbol, where the value refers to something like ‘C:\Windows\….’ directory.

When I checked to my already available value pairs in my PATH string, there are some other directory which are pointed by other application which i use recently.

The overall PATH string of mine is as follows, with the Ruby22\bin already added in front(I’ve installed the latest version of Ruby); and the second value onwards is the one which is being used by Sybase.

Hope to find you well. Did you fix this?
I’m not really sure I understand your question, maybe you could come up with a print screen to enforce what you said and make it more clear.
In case my answer and this comment does not answer your question, please come back with more details and some print screens ( you can send the screens at bitpsychobyte@yahoo.com ).

There is no reason for you to have more than a PATH entry per program.
You already have this for Ruby: C:\Ruby22\bin
I think that the only way you could get conflicts is if you have more PATH entries for the same software (different versions) for example a PATH entry for each Ruby version in case somehow you end up having more versions.

Given the PATH entries you already pasted, I think it should be ok. No need to add my path as I have C:\Ruby193\bin because that was the latest at the given time of this article. You also shouldn’t even modify it (and I’m sure I wrote this in the article). I just mentioned it to check if it’s there and for possible troubleshooting but normally, the path entry is added by the program installation process. You should move on with the article and follow the next steps, don’t add another entry.

Didn’t have the chance to test this on Windows 8 yet, maybe in the future but for now thanks for the update that it doesn’t work on Win8.
Will have a look into it and hopefully it will help others if it will be too late for you.

Hello Guys, First I’d like to say thank you for all your help. I’m a first time user and trying to understand how to make a path with Notepad ++ and ruby. I followed the instruction above but am still having problems. I think my problem is with my not understanding how and or where to save a ruby file with the .rb extension in notepadd++ because I have done all of the steps but can’t seem to not get either a syntax error or ruby not seeing the file at all. I’m running ruby 1.9.3. I went into the installer bin but DID not see a path there so i did everything manually.

Well, I’m not sure I’m the best guy to answer to this question as in my daily job I am a network administrator with a bit of a more expanded responsibilities into the system administration area. That’s how I got in touch with Ruby, by experimenting on some projects.

As for what tech businesses languages are preferred, it all depends on the area of interest for that specific business or for the ones that hire/seek programmers and it is always changing. As a trend I saw a lot of people heading towards Java the last months, with an increased activity on the Java and Eclipse topics.

The thing is that if you really want to know what the market is searching for, if this was the real question and I got it well, I would scout forums that focus on programming, like the ones below but not only:

Do not Copy + Paste the HTML code from above : cmd /K ruby “$(FULL_CURRENT_PATH)”
First Paste it in notepad to clear the HTML special characters and then copy it from Notepad and paste it to the Run Command of Notepad++