We recently installed Nim programming language on Debian 10. Now it is FreeBSD 12’s turn.
Nowadays, almost everything is done with the help of a computer and a program. And the programs are made through a programming language. That is why it must be efficient languages with new technical features that can be brought to the program and the end-user. Today we will teach you how to install Nim programming language on FreeBSD 12.
To quote the website of this programming language:
Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada, and Modula.
This gives us a pretty good idea that the language meets everything needed to create modern applications.
Like all modern languages, it has versions for Windows, Linux, macOS, and BSD. This makes it possible to run on almost all current systems. This also makes it possible for the programmer to choose the environment where he feels best.
Nim is an object-oriented language with a syntax similar to Python‘s with even similar characteristics.
So, let us get to work.
Installing Nim programming language on FreeBSD 12
Nim is available in the official FreeBSD 12 repositories, but the latest stable version is not available. So it is recommended that you download the source code and compile it.
However, if you want to install it without any problems, just run the following command:
:~$ sudo pkg install nim
And now you can start working.
However, in this tutorial, what we are looking for is to install the latest stable version. So to do this, you have to download the source code of the language.
To do this, I will use a tool called wget. Then, the first step is to install it.
:~$ sudo pkg install wget
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 3 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
Number of packages to be installed: 3
The process will require 6 MiB more space.
1 MiB to be downloaded.
Proceed with this action? [y/N]:
When the installation is finished, we can start the download using it. At the time of writing this post, the latest stable version of Nim is 1.2.0.
:~$ wget -c https://nim-lang.org/download/nim-1.2.0.tar.xz
--2020-04-10 06:47:52-- https://nim-lang.org/download/nim-1.2.0.tar.xz
Resolving nim-lang.org (nim-lang.org)... 188.8.131.52, 184.108.40.206, 2606:4700:3036::681c:134f, ...
Connecting to nim-lang.org (nim-lang.org)|220.127.116.11|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5869428 (5.6M) [application/octet-stream]
Saving to: 'nim-1.2.0.tar.xz'
nim-1.2.0.tar.xz 100%[=====================================================================================>] 5.60M 84.4KB/s in 50s
2020-04-10 06:48:43 (115 KB/s) - 'nim-1.2.0.tar.xz' saved [5869428/5869428]
After the download, we have to decompress the file.
:~$ tar xvfj nim-1.2.0.tar.xz
This will generate a folder called nim-1.2.0. Access it and start compiling Nim.
Access it and start compiling Nim.
:~$ cd nim-1.2.0
:~$ sh build.sh
Then, the Nim package must be further built to generate the binary for FreeBSD 12.
:~$ bin/nim c koch
So, finish the creation of the package with this last command:
~$ ./koch tools
Now yes, Nim is installed on FreeBSD 12.
The compiler and tool binaries live inside the bin directory. To test it, access the folder and display the current version.
:~$ cd nim-1.2.0/bin/
:~$ ./nim -version
Testing Nim programming language on FreeBSD 12
Before testing the installation, make Nim available as a command from any location.
To do this, it is advisable to first rename the folder to a simpler one.
:~$ cd ~
:~$ mv nim-1.2.0 nim
If you want you can move it to a more discreet directory. In my case, I’ll leave it right here.
Now to make it available as a command, edit the user profile file.
:~$ nano ~/.profile
And add the following content:
Remember to modify the route where Nim is located. In this case, that’s the way it looks to me.
Then log out and log back in.
Now, create a new test file called hello.nim and add the following code:
:~$ nano hello.nim
echo "Hi, Osradar"
Save and close the file.
Then compile it with the following command:
:~$ nim c hello.nim
And run it:
So, Nim is ready for you to use it in your system.
Programming is very important nowadays, so it requires programming languages to match. Today we have taught you how to install Nim on FreeBSD 12 so you can have an ideal partner to make your applications.
Please share this post and join our Telegram channel.