deno install
Command line usage
deno install [OPTIONS] [cmd]...Installs dependencies either in the local project or globally to a bin directory.
Local installation
Add dependencies to the local project's configuration (deno.json / package.json) and installs them in the package cache. If no dependency is specified, installs all dependencies listed in the config file. If the --entrypoint flag is passed, installs the dependencies of the specified entrypoint(s).
deno install
deno install jsr:@std/bytes
deno install npm:chalk
deno install --entrypoint entry1.ts entry2.ts
Global installation
If the --global flag is set, installs a script as an executable in the installation root's bin directory.
deno install --global --allow-net --allow-read jsr:@std/http/file-server
deno install -g https://examples.deno.land/color-logging.ts
To change the executable name, use -n/
--name
:
deno install -g --allow-net --allow-read -n serve jsr:@std/http/file-server
The executable name is inferred by default:
- Attempt to take the file stem of the URL path. The above example would become
file_server. - If the file stem is something generic like
main,mod,indexorcli, and the path has no parent, take the file name of the parent path. Otherwise settle with the generic name. - If the resulting name has an
@...suffix, strip it.
To change the installation root, use
--root
:
deno install -g --allow-net --allow-read --root /usr/local jsr:@std/http/file-server
The installation root is determined, in order of precedence:
-
--rootoption -
DENO_INSTALL_ROOTenvironment variable $HOME/.deno
These must be added to the path manually if required.
Type checking options
--check
Set type-checking behavior. This subcommand type-checks local modules by default, so adding --check is redundant If the value of "all" is supplied, remote modules will be included. Alternatively, the 'deno check' subcommand can be used.
--no-check
Skip type-checking. If the value of "remote" is supplied, diagnostic errors from remote modules will be ignored.
Dependency management options
--cached-only
Require that remote dependencies are already cached.
--frozen
Error out if lockfile is out of date.
--import-map
Load import map file from local file or remote URL.
--lock
Check the specified lock file. (If value is not provided, defaults to "./deno.lock").
--no-lock
Disable auto discovery of the lock file.
--no-npm
Do not resolve npm modules.
--no-remote
Do not resolve remote modules.
--node-modules-dir
Sets the node modules management mode for npm packages.
--reload
Short flag: -r
Reload source code cache (recompile TypeScript) no value Reload everything jsr:@std/http/file-server,jsr:@std/assert/assert-equals Reloads specific modules npm: Reload all npm modules npm:chalk Reload specific npm module.
--vendor
Toggles local vendor folder usage for remote modules and a node_modules folder for npm packages.
Options
--allow-scripts
Allow running npm lifecycle scripts for the given packages Note: Scripts will only be executed when using a node_modules directory (--node-modules-dir).
--cert
Load certificate authority from PEM encoded file.
--config
Short flag: -c
Configure different aspects of deno including TypeScript, linting, and code formatting Typically the configuration file will be called deno.json or deno.jsonc and automatically detected; in that case this flag is not necessary.
--dev
Short flag: -D
Add as a dev dependency.
--entrypoint
Short flag: -e
Install dependents of the specified entrypoint(s).
--env-file
Load environment variables from local file Only the first environment variable with a given key is used. Existing process environment variables are not overwritten, so if variables with the same names already exist in the environment, their values will be preserved. Where multiple declarations for the same environment variable exist in your .env file, the first one encountered is applied. This is determined by the order of the files you pass as arguments.
--force
Short flag: -f
Forcefully overwrite existing installation.
--global
Short flag: -g
Install a package or script as a globally available executable.
--location
Value of globalThis.location used by some web APIs.
--name
Short flag: -n
Executable file name.
--no-config
Disable automatic loading of the configuration file.
--root
Installation root.
--seed
Set the random number generator seed.
--v8-flags
To see a list of all available flags use --v8-flags=--help Flags can also be set via the DENO_V8_FLAGS environment variable. Any flags set with this flag are appended after the DENO_V8_FLAGS environment variable.
Debugging options
--inspect
Activate inspector on host:port [default: 127.0.0.1:9229]
--inspect-brk
Activate inspector on host:port, wait for debugger to connect and break at the start of user script.
--inspect-wait
Activate inspector on host:port and wait for debugger to connect before running user code.
Examples
deno install
Use this command to install all dependencies defined in deno.json and/or package.json.
The dependencies will be installed in the global cache, but if your project has a package.json file, a local node_modules directory will be set up as well.
deno install [PACKAGES]
Use this command to install particular packages and add them to deno.json or package.json.
$ deno install jsr:@std/testing npm:express
You can also use deno add which is an alias to deno install [PACKAGES]
If your project has a package.json file, the packages coming from npm will be added to dependencies in package.json. Otherwise all packages will be added to deno.json.
deno install --entrypoint [FILES]
Use this command to install all depenedencies that are used in the provided files and their dependencies.
This is particularly useful if you use jsr:, npm:, http: or https: specifiers in your code and want to cache all the dependencies before deploying your project.
import * as colors from "jsr:@std/fmt/colors";
import express from "npm:express";
$ deno install -e main.js
Download jsr:@std/fmt
Download npm:express
If you want to set up local node_modules directory, you can pass --node-modules-dir=auto flag.
Some dependencies might not work correctly without a local node_modules directory.
deno install --global [PACKAGE_OR_URL]
Use this command to install provide package or script as a globally available binary on your system.
This command creates a thin, executable shell script which invokes deno using the specified CLI flags and main module. It is placed in the installation root's bin directory.
Example:
$ deno install --global --allow-net --allow-read jsr:@std/http/file-server
Download jsr:@std/http/file-server...
✅ Successfully installed file-server.
/Users/deno/.deno/bin/file-server
To change the executable name, use -n/--name:
deno install -g -N -R -n serve jsr:@std/http/file-server
The executable name is inferred by default:
- Attempt to take the file stem of the URL path. The above example would become 'file-server'.
- If the file stem is something generic like 'main', 'mod', 'index' or 'cli', and the path has no parent, take the file name of the parent path. Otherwise settle with the generic name.
- If the resulting name has an '@...' suffix, strip it.
To change the installation root, use --root:
deno install -g -N -R --root /usr/local jsr:@std/http/file-server
The installation root is determined, in order of precedence:
-
--rootoption -
DENO_INSTALL_ROOTenvironment variable $HOME/.deno
These must be added to the path manually if required.
echo 'export PATH="$HOME/.deno/bin:$PATH"' >> ~/.bashrc
You must specify permissions that will be used to run the script at installation time.
deno install -g -N -R jsr:@std/http/file-server -- -p 8080
The above command creates an executable called file_server that runs with network and read permissions and binds to port 8080.
For good practice, use the import.meta.main idiom to specify the entry point in an executable script.
Example:
// https://example.com/awesome/cli.ts
async function myAwesomeCli(): Promise<void> {
// -- snip --
}
if (import.meta.main) {
myAwesomeCli();
}
When you create an executable script make sure to let users know by adding an example installation command to your repository:
# Install using deno install
$ deno install -n awesome_cli https://example.com/awesome/cli.ts
Native Node.js addons
A lot of popular packages npm packages like npm:sqlite3 or npm:duckdb depend on "lifecycle scripts", eg. preinstall or postinstall scripts. Most often running these scripts is required for a package to work correctly.
Unlike npm, Deno does not run these scripts by default as they pose a potential security vulnerability.
You can still run these scripts by passing the --allow-scripts=<packages> flag when running deno install:
deno install --allow-scripts=npm:sqlite3
Install all dependencies and allow npm:sqlite3 package to run its lifecycle scripts.
Uninstall
You can uninstall dependencies or binary script with deno uninstall command:
$ deno uninstall express
Removed express
$ deno uninstall -g file-server
deleted /Users/deno/.deno/bin/file-server
✅ Successfully uninstalled file-server
© 2018–2024 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/runtime/reference/cli/install