How to Install Deno on macOS
Deno is a simple, modern and secure runtime for JavaScript and TypeScript, by the creator of Node.js himself, Ryan Dahl. Deno uses the Chrome v8 engine and is built with Rust. The project just reach version 1.0 and got many people in the JavaScript community interested.
In this tutorial I will show you how we can install Deno for macOS in a matter of seconds using Curl.
1. Use Curl in your terminal to install Deno
curl -fsSL https://deno.land/x/install/install.sh | sh
A successful response should give you further details on how we can configure your bash or zsh profile.
Deno was installed successfully to /Users/username/.deno/bin/deno
Manually add the directory to your $HOME/.zshrc (or similar)
export DENO_INSTALL="/Users/username/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
Run '/Users/username/.deno/bin/deno --help' to get started
2. Manually add the directory to your $HOME/.zshrc or $HOME/.bash_profile
locate the $HOME/.zshrc or $HOME/.bash_profile (depending on what you use) file and add the following lines in the file. Make sure to use the correct information provided in the terminal after a successful install.
#deno
export DENO_INSTALL="/Users/username/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
3. Verify that everything was installed an configured correctly
We can verify that everything was installed and configured correctly by running the deno welcome.ts test project.
deno run https://deno.land/std/examples/welcome.ts
☝️ Notice If you get zsh: command not found: deno or similar error, restart your terminal or open a new tab and run the command once again, so that the changes to your bash or szh profile can take effect.
Download https://deno.land/std/examples/welcome.ts
Warning Implicitly using master branch https://deno.land/std/examples/welcome.ts
Compile https://deno.land/std/examples/welcome.ts
Welcome to Deno 🦕
4. Create an example project & server
create a new project folder and add a main.ts file
import { serve } from "https://deno.land/std@0.55.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
req.respond({ body: "Hello World\n" });
}
Then run the project with a --allow-read and --allow-net flag
deno run --allow-read --allow-net main.ts
Deno should start downloading dependencies, compiling the project, starting the server and console logging the localhost address.
Download https://deno.land/std@0.55.0/http/server.ts
Download https://deno.land/std@0.55.0/encoding/utf8.ts
Download https://deno.land/std@0.55.0/io/bufio.ts
Download https://deno.land/std@0.55.0/testing/asserts.ts
Download https://deno.land/std@0.55.0/async/mod.ts
Download https://deno.land/std@0.55.0/http/_io.ts
Download https://deno.land/std@0.55.0/io/util.ts
Download https://deno.land/std@0.55.0/textproto/mod.ts
Download https://deno.land/std@0.55.0/http/http_status.ts
Download https://deno.land/std@0.55.0/async/deferred.ts
Download https://deno.land/std@0.55.0/async/delay.ts
Download https://deno.land/std@0.55.0/async/mux_async_iterator.ts
Download https://deno.land/std@0.55.0/fmt/colors.ts
Download https://deno.land/std@0.55.0/testing/diff.ts
Download https://deno.land/std@0.55.0/path/mod.ts
Download https://deno.land/std@0.55.0/bytes/mod.ts
Download https://deno.land/std@0.55.0/path/_constants.ts
Download https://deno.land/std@0.55.0/path/win32.ts
Download https://deno.land/std@0.55.0/path/posix.ts
Download https://deno.land/std@0.55.0/path/common.ts
Download https://deno.land/std@0.55.0/path/separator.ts
Download https://deno.land/std@0.55.0/path/_interface.ts
Download https://deno.land/std@0.55.0/path/glob.ts
Download https://deno.land/std@0.55.0/path/_util.ts
Download https://deno.land/std@0.55.0/path/_globrex.ts
Compile file:///Users/username/deno/deno-test/main.ts
http://localhost:8000/
Your Deno application is now up and running, you can visit your localhost address (http://localhost:8000/) and be greeted with the Hello World.