Ubuntu下nim language环境配置

2015/02/22 13:51
阅读数 444

Getting Started

Nim is a powerful statically typed language that allows the programmer expressiveness without compromising run-time performance. As a general purpose programming language, it gives the same sort of power and performance as C++, but in a nicer package and with even more powerful tools!

Note: The Nim compiler requires a C compiler to compile software. GCC is recommended on Linux and Clang on Mac.

Downloading from Git

To install Nim from git, ensure that you have gcc installed on Windows, Linux, and BSDs and clang on Mac. Afterwards, run the following series of commands to download and bootstrap Nim:

 $ git clone -b master git://github.com/Araq/Nimrod.git
 $ cd Nimrod
 $ git clone --depth 1 git://github.com/nimrod-code/csources
 $ cd csources
 $ sh build.sh
 $ cd ..
 $ bin/nim c koch
 $ ./koch boot -d:release

Once compiled, you may want to add the bin directory to your path for easy access.


Nimble is a beta-grade package manager for the Nim programming language.

On Unix operating systems Nimble can be compiled and installed with two simple commands. After successfully grabbing the latest Nim compiler simply execute the following commands to clone nimble, compile it and then install it.

$ git clone https://github.com/nim-lang/nimble.git
$ cd nimble
$ nim c -r src/nimble install

After these steps nimble should be compiled and installed. You should then add ~/.nimble/bin to your$PATH. Updating nimble can then be done by executing 

$ nimble install nimble



Aporia is an IDE for the Nim programming language. Aporia uses GTK as the default toolkit, and the gtksourceview for the text editor component.


  • GTK

  • GtkSourceView (libgtksourceview-2.0.so)

  • PCRE

Use your linux package manager to install the dependencies.


To compile Aporia you need the latest version of the nim compiler, preferably the unstable release from github. Aporia sometimes relies on bug fixes which have not yet made it to a stable release.

You can build it by running :

$ nim c aporia

 or by using nimble :

$ nimble build

You can also quickly install it using nimble without the need to clone this repo yourself, just execute:

$ nimble install aporia@#head


The code for a simple program is as follows:

import tables, strutils

var wordFrequencies = initCountTable[string]()

for line in stdin.lines:
  for word in line.split(", "):

echo "The most frequent word is '", wordFrequencies.largest, "'"

Save this text as frequentword.nim. To compile and execute the program, the following command should be run with some input words :

$ nim c -r --verbosity:0 frequentword.nim
大黄, 小白, 大黄, 小白, 小白, 小白, 大黄
The most frequent word is '(key: 小白, val: 4)'

The command has several elements:

  • c is an alias for compile, which compiles the Nim sources into C and then invokes the C compiler on them

  • -r is an alias for --run, which runs the program

  • --verbosity:0 makes the compiler only output essential messages, since by default it also outputs some debugging messages. From now on, we assume that --verbosity:0 is set

  • ./frequentword.nim is the path to the source you want to compile

0 收藏
0 评论
0 收藏