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: https://notepad-plus-plus.org/downloads/v7.8.8/
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
Open Notepad++, select Settings – Preferences. Click on Language Menu/Tab Settings.
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.
Rating: 4.4/5 (9 votes cast)
Run Ruby program and compile sources using Notepad++, 4.4 out of 5 based on 9 ratings