Cyberithub

How to Install OCaml Programming Language on Ubuntu 20.04 LTS

Advertisements

In this article, I will take you through the steps to install OCaml Programming Language on Ubuntu 20.04 LTS but before that let me ask you a quick question. Do you know any major IT Organization who is using OCaml programming language very frequently to develop multiple number of tools. Well, there are many tech giants currently using this programming language in which one of the most popular is Meta(formerly Facebook). The reason is pretty simple. It is because of the number of features OCaml provides in the Functional Programming paradigm.

While there are many functional programming languages are available today but OCaml is an Industrial Strength Programming language which support functional, imperative and object-oriented Styles. This gives lot of flexibility to developer and programmers. More on OCaml Official documentation.

How to Install OCaml Programming Language on Ubuntu 20.04 LTS

How to Install OCaml Programming Language on Ubuntu 20.04 LTS

Also Read: How to Install Haskell Platform on Ubuntu 20.04 LTS

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS System.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get utility installed in the Server.

 

Step 2: Update Your Server

If you have not updated your System from quite sometime then it is absolutely necessary that you run update once by using apt-get update command. This will update all the installed packages to the latest version and will keep the System up to date.

root@localhost:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Hit:4 http://ppa.launchpad.net/ansible/ansible/ubuntu focal InRelease
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:6 http://ppa.launchpad.net/micahflee/ppa/ubuntu focal InRelease
Get:7 https://apt.releases.hashicorp.com focal InRelease [4,419 B]
Get:8 https://packages.microsoft.com/repos/edge stable InRelease [7,342 B]
Hit:9 https://packages.grafana.com/oss/deb stable InRelease
Get:10 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,302 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [553 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [279 kB]
Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/main DEP-11 48x48 Icons [60.8 kB]
Get:14 http://in.archive.ubuntu.com/ubuntu focal-updates/main DEP-11 64x64 Icons [98.3 kB]

 

Step 3: Install OCaml

In the next step, you can install OCaml programming language by using apt-get install ocaml -y command as shown below.

root@localhost:~# apt-get install ocaml -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
racket-common racket-doc
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
ledit ocaml-base ocaml-base-nox ocaml-compiler-libs ocaml-interp ocaml-man ocaml-nox
Suggested packages:
ocaml-doc tuareg-mode
The following NEW packages will be installed:
ledit ocaml ocaml-base ocaml-base-nox ocaml-compiler-libs ocaml-interp ocaml-man ocaml-nox
0 upgraded, 8 newly installed, 0 to remove and 8 not upgraded.
Need to get 85.1 MB of archives.
After this operation, 371 MB of additional disk space will be used.

 

Step 4: Check OCaml Version

After OCaml successful installation, you can check its version by using ocaml --version command as shown below. As you can see current installed version is 4.08.1.

root@localhost:~# ocaml --version
The OCaml toplevel, version 4.08.1

 

Step 5: Write Your First Program

Now that OCaml is installed successfully in your System, it is time to write your First Program. You can do that by executing your code interactively with the toplevel. You can launch toplevel using ocaml command. Then you can write OCaml sentence here ending with ;; which denotes the end of the sentence.

root@localhost:~# ocaml
OCaml version 4.08.1

# "Hello Worlds!";;
- : string = "Hello Worlds!"

 

Step 6: Remove OCaml

Once you are done using OCaml programming language then you can remove its packages by using apt-get remove OCaml -y command as shown below.

root@localhost:~# apt-get remove ocaml -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
ledit ocaml-base ocaml-base-nox ocaml-compiler-libs ocaml-interp ocaml-man ocaml-nox racket-common racket-doc
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
ocaml
0 upgraded, 0 newly installed, 1 to remove and 7 not upgraded.
After this operation, 267 kB disk space will be freed.
(Reading database ... 271183 files and directories currently installed.)
Removing ocaml (4.08.1-8) ...

You might have noticed that during installation a lot of dependencies got installed along with OCaml package which will not get removed automatically after its uninstallation. So to remove all these packages you need to run apt autoremove -y command as shown below. This will remove all automatically installed packages which are no longer required.

root@localhost:~# apt autoremove -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
ledit ocaml-base ocaml-base-nox ocaml-compiler-libs ocaml-interp ocaml-man ocaml-nox racket-common racket-doc
0 upgraded, 0 newly installed, 9 to remove and 7 not upgraded.
After this operation, 845 MB disk space will be freed.
(Reading database ... 271168 files and directories currently installed.)
Removing ledit (2.04-4build1) ...
Removing ocaml-base (4.08.1-8) ...
Removing ocaml-man (4.08.1-8) ...
Removing racket-common (7.2+dfsg1-2ubuntu3) ...
Removing racket-doc (7.2+dfsg1-2ubuntu3) ...
Removing ocaml-nox (4.08.1-8) ...
Removing ocaml-interp (4.08.1-8) ...
Removing ocaml-base-nox (4.08.1-8) ...
Removing ocaml-compiler-libs (4.08.1-8) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...

Leave a Comment