Running Nim on a Cloud IDE with Git

Joe Bland
4 min readMar 11, 2015

Notes on installing and working with the nim-lang programming language.

What is Nim? What is Nim not?

Nim (formerly Nimrod, AKA Nim-lang) is a relatively new programming language. Code written in Nim is compiled to the C language, and C runs on almost every operating system. Nim seems to be created by one guy and a band of conspirators, and is MIT license, so is reasonably independent.

Because Nim compiles to C, the things you make with it are typically apps/programs, not websites or webapps. But, in fact, you can read about doing exactly that here . Currently, Nim is in pre-1.0 release, so it’s not labeled ‘ready for production’.

Environment

I decided to use a cloud IDE and the only one I’ve found which will install Nim is Codeanywhere, having tried a bunch of others, using the free offering of all. I prefer the interface of Cloud9, where I’m working on Ruby on Rails, but Nim would not install there, giving memory issues.

By the way, you can see my study notes about Ruby on Rails at my journal called Web Design &c.

The Nim How To

I’m following along the How I Start Nim tutorial by Dennis Felsing, which is reasonably good. While I was learning Ruby on Rails, I used the exceptional Ruby on Rails Tutorial and although How I Start is not intended to be as thorough, it’s similar and quite clear.

There are some long lines of code and of course the syntax is critical. Codeanywhere terminal is either different to or lacking the features of less geeky text interfaces, so check every line before you hit ‘enter’.

The notes below should be read alongside How I Start, and are an attempt to fill in some gaps for the less experienced, or in relation to the Nim/Codeanywhere/Bitbucket set up.

Some Linux Stuff

The line

$ echo 'export PATH=$PATH:$HOME/.nimble/bin' >> ~/.profile

puts the Nimble package into the ‘path’, meaning you can run Nimble without specifying the complete address of the thing. Somehow I stuffed this up, but luckily, you can edit .profile in the Vim text editor, by running

$ sudo vim ~/.profile

In Vim, you can save and exit by pressing ‘esc’ then entering:

$ :wq

Vim is a bit foreign to me, so here’s a handy list of Vim commands, to enter after ‘esc’ (from here):

Command—Description
…………………………………………….
q — Quit
q!
— Quit without saving changes i.e. discard changes
r fileName
— Read data from file called fileName
wq
— Write and quit (save and exit)
w fileName
— Write to file called fileName (save as)
w! fileName
— Overwrite to file called fileName (save as forcefully)
…………………………………………….

Creating the custom stack

Before proceeding with the “Project Setup” section of the How I Start tute, right click on Devbox/nim in Codeanywhere, and select “Create Custom Stack” to make a copy of this set up, which can be used for other projects.

After doing the first section of “Project Setup” is a good time to start version control with Git.

Implementing Git with Bitbucket

To set up version control for your project, first ensure that you’re in the project directory at the terminal, so your prompt should be something like:

~/cabox/workspace/my_project_name $

Start Git by creating a new, empty repo, by entering:

$ git init

then, let Git know who you are; set a default; and create the co shortcut for checkout:

$ git config --global user.email "you@youremail.com"
$ git config --global user.name "Your Name"
$ git config --global push.default matching
$ git config --global alias.co checkout

Next create the .gitignore file for things Git should not track. So use the touch command to create the file, then vim to edit it’s contents:

$ touch .gitignore
$ vim .gitignore

In Vim, just add these lines, then hit ‘esc’ then type ‘:wq’ and hit ‘enter’ to save and exit:

nimcache/
*.swp

Now Git is set up, add all the project files to the repo; and use Commit to tell Git to keep the changes on the local system, with the -m flag to signal a message you’re adding to this commit:

$ git add -A
$ git commit -m "Initialize repository"

You’ll need to find out the SSH key, so run

$ cat ~/.ssh/id_rsa.pub

Use the right mouse button to copy the resulting output, including ‘ssh-rsa’ at the start. Go to your/sign up for a Bitbucket account, and paste this in the appropriate field at Manage Account/SSH Keys/Add key. Make a new repo in Bitbucket, noting the name, for example nim_trial.git.

Back at Codeanywhere, ensuring the prompt is still at the my_project_name directory, enter:

$ git remote add origin git@bitbucket.org:<username>/nim_trial.git
$ git push -u origin --all

The first line sets up the connection, the second line pushes a copy of the repo from the local system to Bitbucket. Obviously, replace <username> with your Bitbucket username, and nim_trial.git with whatever you called the repo in Bitbucket.

Outro

I think this is enough for one article now!

You’re now good to go with any project you want to take on — including the samples in the How I Start tutorial; this one on Creating a Simple Web Application; and many others you might find around.

--

--