Making a Deno Script globally available

Viewed 170

Have built myself a CLI tool for my more generic projects using Deno. It's useful, does the stuff I need it to do. However, I'm looking into achieving something similar to npm install -g <my-git-repo> but with Deno.

I understand I could easily create a ~/.myDeno with a bash script and adding export PATH=$PATH:~/.myDeno but was wondering if there was a proper process to follow to achieve this with Deno. As I have thus far been unable to find one.

2 Answers

You could use deno install or deno compile to create executables from Deno code.

deno install will install your CLI tool in $HOME/.deno/bin or a custom directory when you set the DENO_INSTALL_ROOT environment variable.

deno_compile will create a self-contained binary including the runtime and dependencies, as was answered in this thread. It would make the executable more stand-alone but it increases the size of the compiled source.

It's up to you which one you prefer, but they can both work to execute a Deno module 'globally'

For anyone else deno install <dir|git repo> installs it the .deno folder in your home directory and provides an PATH amendment you need to add to your bash profile.

Related