Howtodojo logo
  • Home 
  • About 
  • Certifications 
  • Sample Database 
  • Cheatsheet 
  • Glossary 
  • Blog 
  • Tags 
  1.   Blog
  1. Home
  2. Blog
  3. How to Install nim on Ubuntu 16.04

How to Install nim on Ubuntu 16.04

Share via
Howtodojo
Link copied to clipboard

In this tutorial we'll learn how to install Nim on Ubuntu 16.04. We will install Nim from the Ubuntu repository and also install nim from source.

On this page
Overview   Install nim From Repository   Hello Nim   Install nim From Source   Summary  

Overview  

In this tutorial we’ll learn how to install Nim on Ubuntu 16.04. We will install Nim from the Ubuntu repository and also install nim from source.

Nim is :

systems and applications programming language. Statically typed and compiled, it provides unparalleled performance in an elegant package.

Nim provides:

  • High-performance garbage-collected languag
  • Compiles to C, C++ or JavaScript
  • Produces dependency-free binaries
  • Runs on Windows, MacOS, Linux and more

Install nim From Repository  

Nim is available on Ubuntu 16.04 repository.

To install Nim we can run the command below.

sudo apt-get update
sudo apt-get install -y nim
```bash

Now we can check Nim version installed with contents below:

```bash
$ nim -v
Nim Compiler Version 0.12.0 (2015-11-02) [Linux: amd64]
Copyright (c) 2006-2015 by Andreas Rumpf

active boot switches: -d:release

Hello Nim  

Let’s create hello world application for Nim. Create new file called hello.nim with contents below:

echo "Hello Nim! - howtodojo.com"
```bash

Compile the source code using the command below.

```bash
$ nim c hello.nim
Hint: system [Processing]
Hint: hello [Processing]
CC: hello
CC: system
Error: execution of an external compiler program 'gcc -c  -w  -I/usr/lib/nim -o /home/ubuntu/nimcache/hello.o /home/ubuntu/nimcache/hello.c' failed with exit code: 32512

/bin/sh: 1: gcc: not found

We still get an error since we don’t have GCC installed. Yes, nim relies on the c / c++ compiler to compile.

Install GCC using the command below

$ sudo apt-get install gcc
```bash

Now let's recompile our `hello.nim` source code.

```bash
$ nim c hello.nim
Hint: system [Processing]
Hint: hello [Processing]
CC: hello
CC: system
Hint:  [Link]
Hint: operation successful (9852 lines compiled; 0.910 sec total; 14.148MB; Debug Build) [SuccessX]

Source code compiled sucessfully. The binary file name is hello. We can check the file type using file command.

$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=fe9a2d66209c2adb082ae63e15fc35e8f991a322, not stripped
```bash

We can see above that hello is a ELF / Linux binary file.

Now let's execute the hello application.

```bash
$ ./hello
Hello Nim! - howtodojo.com

The application runs successfully.

Install nim From Source  

As you can see above, Nim version shipped with Ubuntu 16.04 is 0.12.0.

At the time of this writing, the latest stable version of Nim is 0.17.2. In this section, we’ll learn how to install nim from the source.

We can download the latest version of Nim from Nim install Unix page.

Download nim source code using wget.

$ wget -c https://nim-lang.org/download/nim-0.17.2.tar.xz
```bash

Download the sha256 file that contains a hash for nim source code file. We will use this file to ensure the integrity of the nim source code.

```bash
$ wget -c https://nim-lang.org/download/nim-0.17.2.tar.xz.sha256  

Now let’s check nim source code integrity using sha256sum command

$ sha256sum -c nim-0.17.2.tar.xz.sha256
nim-0.17.2.tar.xz: OK
```bash

If should output OK as shown below. If not then you will need to redownload nim source code.

Extract nim source code using command below.

```bash
$ tar xJf nim-0.17.2.tar.xz

Go to extracted directory

$ cd nim-0.17.2
```bash

Run the command below to build nim and tools. We assume that you already install `gcc` before compiling Nim.

```bash
$ ./build.sh
$ bin/nim c koch
$ ./koch tools

Install nim to /opt directory.

$ sudo ./install.sh /opt
```bash

Check the new Nim version installed on `opt`.

```bash
$ /opt/nim/bin/nim -v
Nim Compiler Version 0.17.2 (2017-09-07) [Linux: amd64]
Copyright (c) 2006-2017 by Andreas Rumpf

git hash: 811fbdafd958443ddac98ad58c77245860b38620
active boot switches: -d:release

Summary  

In this tutorial, we learn how to install Nim from the Ubuntu repository. We learn how to compile Hello Nim! source code to test our installation.

We also learn how to install Nim from source code. Have fun with Nim!

 How to Install julia on Ubuntu 16.04
How To Install Redis On Ubuntu 16.04 
On this page:
Overview   Install nim From Repository   Hello Nim   Install nim From Source   Summary  
Follow me

We publish tutorials, tips and tricks about Linux, open source, cloud computing, and infrastructure

     
Copyright © 2012 - 2025 howtodojo.com. |
Howtodojo
Code copied to clipboard