How to install the Deno JavaScript Runtime on Ubuntu 20.04?

Overview

With an emphasis on security, the developer work experience, and connectivity with common browser APIs, the Node.js creators developed Deno, a new JavaScript runtime.

Deno utilises the same V8 JavaScript engine as Node.js and the Chrome browser, but it also includes secure sandboxing, integrated TypeScript support, and a curated collection of standard modules.

In this article, we'll download and set up Deno on Ubuntu 20.04, then try it out by running a hello world statement.

Prerequisites

There are certain prerequisites that need to be met before you begin.

  • Ubuntu version 20.04 or any other Linux equipped system

  • A regular user (non-root) having Sudo privileges

  • Internet connection

Get Started

Step 1 - Downloading Deno

Deno comes with a single executable file, allowing for manual download and installation. Go to the directory first, then download 30 MB file.

  • Here, we will use the /tmp directory:

cd /tmp
  • Next, use curl to request Deno's most recent release from GitHub:

curl -Lo "deno.zip" "https://github.com/denoland/deno/releases/latest/download/deno-x86_64-unknown-linux-gnu.zip"
  • A progress bar will then be visible:

A deno.zip file will be present in your current directory once the download is finished. You will decompress this file and install the deno executable in the following step.

Step 2 - Installing Deno

  • It's time to install Deno after downloading the zip file. Before installing unzip with apt, update your system's package index. To decompress the file, you must first ensure that the unzip command is present on your computer.

sudo apt update
  • After updating your system's package index, apt should be used to install unzip. If you're using sudo for the first time during this session, you could be asked for your password:

sudo apt install unzip
  • After installation, extract the deno executable utilizing unzip and place it in the /usr/local/bin directory:

sudo unzip -d /usr/local/bin /tmp/deno.zip

Unzip is instructed by the -d flag to store the produced file in /usr/local/bin. Keep in mind that you must use sudo above because you are unzipping into an encrypted system directory.

  • Currently, the installation should be finished. Make sure the new /usr/local/bin/deno file has the appropriate owner and rights by using ls to list it:

ls -al /usr/local/bin/deno
  • In order to ensure appropriate operation, use the deno command after adding the --version flag; deno will print out a few version details:

deno --version

Now that Deno has been successfully downloaded and installed, we'll employ it to execute a hello world sentence.

Step 3 - Using the Deno REPL

You can enter the Deno REPL by running the basic deno command without any subcommands. The acronym REPL stands for "read-eval-print loop" and refers to an interactive prompt where statements can be entered, evaluated, and the results printed right away.

REPLs can be a useful tool for programming language exploration.

Now launch the Deno REPL:

deno

Enter the JavaScript hello world example below, and Deno will analyse it and show the results.

This statement produces a JavaScript array (['hello', 'world']), then joins the two words with a space using the array's join() method.

['hello', 'world'].join(' ')

Hit CTRL+D or type close () and hit ENTER to close the Deno REPL.

Conclusion

In this article, you downloaded and installed Deno, tested a basic hello world program using Deno REPL by following the instructions in this step-by-step tutorial.

Last updated