Jul 19 2008
Ruby installer using NSIS (Part 1)
Intro
On a recent project I was challenged with the task to create a Windows installer for Dradis, an application that I have been contributing to. After a bit of research it seemed like our answer was in using NSIS (Nullsoft Scriptable Install System) to assist us in this task.
NSIS in an open source platform for creating Windows installers. It has its own scripting language that you program all your installer logic in and then compiles to a Windows installer executable.
In this series of articles I will introduce you to:
- HM NIS IDE and it’s wizard (Part 1)
- Customising the wizard code (Part 2)
- Challenges with installing to user accounts without administrator rights (Part 3)
The goal
The goal is to create an installer for Acme application. I will customise the installer code as we go along but the main components for installation are:
- Copying our acme_app.rb file to a location on the target machine
- Check if Ruby is installed on the target machine. Install it if it is not the case
- Our application uses SQLite. We need to check if the required files are installed on the target machine and install it if it is not the case.
On the NSIS website you will find plenty of examples and tutorials to get you started. I am however going to jump in a little further ahead and tell you about HM NIS Edit. HM NIS Edit is an Editor/IDE to create your NSIS installers in. I came across it after a little web search and it proved itself to be a very handy tool to use on top of NSIS.
To create a nice installer with options, components, license etc. there is a lot of code that is generic and can fit into a framework followed by a bit of customisation. HM NSIS Edit assists you in this task by providing a wizard. It is from the wizard I’ll start my explanation.
The HM NIS Edit wizard
In the HM NSIS Edit application you have the typical wand and stars icon to start the wizard with. The first couple of screens is pretty straight forward and asks you a number of things about your app. The fun starts at the “Application Files” screen. It is here where you specify the different components (groups) for your application and the files associated.
The application components
For the purpose of my Acme application I create the following components: Ruby, SQLite and Acme app.
1. Ruby
For the Ruby component I do not see the point of wrapping the Ruby one click installer file in our Acme app installer. I decided I’ll make Ruby an install component but picking it for installation will download the Ruby one click installer and execute it. I create the Ruby group in the wizard and do not pick any files, we will add the meat of the download and install later.
2. SQLite
Now we get to the SQLite component. So we create the SQLite group in our wizard. This group consists of two parts: the dll and the Ruby gem.
sqlite3.dll
The dll is easy; it is one file that we need to copy to the system32 folder. So to the right hand side of the wizard window we click the add file icon, browse for the dll that we have ready on our machine and select the destination directory. The destination directory is the directory on the target machine where the file will be copied to. We need it in the system32 folder so we choose $SYSDIR from the drop down box.
SQLite gem
The most common way to install Ruby gem is with the command line command:
gem install GEMNAME --remote
In older GEM versions you could not however state the platform that you are installing the gem to from the command line, it is an option that is given to you just after running the “gem install GEMNAME –remote” command.
The above will not work very nice with our installer as we want the installer to deal with this and not require input from the user on gem installation. However you can use --local instead of --remote and just specify the local file from which the gem should be installed. In this case the installation does not require from you to supply the platform.
So I downloaded the sqlite3-ruby-1.2.1-mswin32.gem file from RubyForge and added it to the files to be installed as we did with the dll, however in this case just copy it to the $INSTDIR. We will add the meat to run the gem install GEMNAME --remote command later.
3. Acme app
Now we get to our acme_app.rb source file. As for the previous components we create a new component group called Acme app. After the component has been created be associate ou acme_app.rb source file with it as we did with the SQLite files. We set the $INSTDIR to be our target folder on the target machine.
Note - If your application code is more than one file you can select a directory tree to be associated with the component instead of just a single file at a time.
At this point you component list should look something similar to what you see in the figure below.
Completing the rest of the wizard is quite straight forward. Remember that if you want to execute an executable (for instance if you want to call notepad to open a file at the end of installation) you have to give the full path to the executable (for example “$SYSDIR\notepad.exe some-text-file”).
Finishing the wizard will give you a code file that you can compile in HM NIS Edit and it will supply you with the install executable.
That’s it for now
- but there is more
I have left a few things out that the wizard could not do to customise our installer. I will have to do some tweaking to the code for this purpose. This will be covered in Part 2.





