How to Install TypeScript on Ubuntu (26.04, 24.04, 22.04)

Last updated Tuesday, March 3, 2026 7:25 am 5 min read

Type errors are cheap to fix early and expensive to debug after deployment. Install TypeScript on Ubuntu to catch those errors during compilation instead of production runtime. This walkthrough installs the tsc compiler with npm and validates it with a quick compile test on Ubuntu 26.04, 24.04, and 22.04.

Beyond catching bugs early, TypeScript adds autocompletion, inline documentation, and safe refactoring to any editor that supports the language server. Ubuntu does not package a typescript compiler in its default repositories, so the standard path is npm after you confirm a supported Node.js version.

Install TypeScript on Ubuntu

Start by refreshing package metadata, then verify your Node.js version before installing the compiler.

Install ScopeCommandBest For
Global compilersudo npm install -g typescriptCLI access from any directory
Project-local compilernpm install --save-dev typescriptPinned versions per repository

A global install places one shared tsc binary on your PATH, which is convenient for ad-hoc compiles. A project-local install records the exact compiler version in package.json, so every contributor on the team compiles with the same version and avoids silent drift between machines.

The walkthrough below uses the global method because it is the fastest way to validate that tsc works system-wide on Ubuntu.

Update Ubuntu Package Metadata

sudo apt update && sudo apt upgrade

This guide uses sudo for commands that need elevated privileges. If your account is not in the sudoers group, follow this guide to add and manage sudo users on Ubuntu.

Verify Node.js and npm Versions for TypeScript

TypeScript 5.x needs Node.js 14.17 or newer. Confirm your installed versions:

node --version
npm --version

Example output:

v24.14.0
11.9.0

Any Node.js version at or above v14.17.0 satisfies TypeScript 5.x. If your version is lower, install a newer Node.js release on Ubuntu before continuing.

Install Node.js and npm on Ubuntu (If Missing)

If Node.js or npm is not installed, add them from Ubuntu repositories:

sudo apt install nodejs npm

Ubuntu 22.04 ships Node.js 12.x by default, which is too old for TypeScript 5.x. On 22.04, use NodeSource or NVM to get a supported release; install Node.js on Ubuntu covers both methods.

Install the tsc TypeScript Compiler Globally on Ubuntu

Install TypeScript globally so the tsc command is available in any project directory:

sudo npm install -g typescript

Expected output:

added 1 package in 1s

Check TypeScript Version on Ubuntu

tsc --version

Example output:

Version 5.9.3

Create a TypeScript Test Project on Ubuntu

Compile one small file to confirm your TypeScript compiler and Node.js runtime are both working correctly.

Initialize a Project Directory and tsconfig.json

mkdir ts-test-project
cd ts-test-project
tsc --init

Expected output:

Created a new tsconfig.json

This file controls which JavaScript version the compiler targets, how strict type checking is, and where compiled output goes. The defaults work for a quick test. For stricter checks and custom build targets, review the official TypeScript TSConfig reference.

Compile and Run a Hello World TypeScript File

cat > hello.ts <<'EOF'
let message: string = "Hello, World!";
console.log(message);
EOF

tsc hello.ts
node hello.js

The tsc command compiles hello.ts into plain JavaScript (hello.js), stripping away the : string type annotation in the process. This step is required because Node.js and browsers only understand JavaScript; they cannot run TypeScript directly.

Expected output:

Hello, World!

Troubleshoot TypeScript on Ubuntu

Fix tsc Command Not Found on Ubuntu

If your shell returns tsc: command not found, npm installed TypeScript but your shell PATH does not include npm’s global binary directory.

Common error:

bash: tsc: command not found

Diagnose the npm global prefix path:

npm config get prefix

Example output:

/usr/local

For a /usr/local prefix, add /usr/local/bin to your shell PATH and reload your profile:

echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

Verify the fix:

command -v tsc
tsc --version

Expected output:

/usr/local/bin/tsc
Version 5.9.3

Fix EACCES Permission Errors During npm Global Installs

The /usr/local/lib/node_modules directory is owned by root, so npm cannot write there without sudo. Rather than running every global install as root, the safer fix is to redirect npm globals to a directory your user already owns.

Common error:

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'

Apply a user-space npm prefix and update your PATH:

mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
npm install -g typescript

Verify the compiler works without sudo:

tsc --version

Expected output:

Version 5.9.3

Fix TypeScript Errors Caused by an Old Node.js Version

TypeScript 5.x needs Node.js 14.17 or newer, so older Node.js installs can fail during compile or execution.

Check your active Node.js version:

node --version

If the result is lower than v14.17.0, install a supported Node.js LTS release on Ubuntu, then rerun:

sudo npm install -g typescript
tsc --version

Expected output:

Version 5.9.3

Remove TypeScript from Ubuntu

Remove the global TypeScript package first, then clean unused dependencies if you do not need Node.js tooling anymore.

sudo npm uninstall -g typescript

If you also want to remove Node.js and npm from Ubuntu repositories:

sudo apt remove nodejs npm
sudo apt autoremove

Verify TypeScript was removed:

tsc --version

Expected output:

bash: tsc: command not found

Frequently Asked Questions About TypeScript on Ubuntu

Is TypeScript available from Ubuntu default repositories?

No. TypeScript is usually installed through npm, not Ubuntu default repositories. Install Node.js and npm first, then run npm install -g typescript for a system-wide compiler.

Why does Ubuntu show tsc command not found after installation?

This usually means npm’s global binary directory is missing from your PATH. Check npm config get prefix, then add the matching bin path such as /usr/local/bin to your shell profile and reload it.

How do I check if TypeScript is installed on Ubuntu?

Run tsc --version to confirm the compiler is installed and command -v tsc to confirm the executable path. If both commands return output, TypeScript is available in your shell.

Should I install TypeScript globally or per project on Ubuntu?

Use a global install for quick CLI access across many folders. For production repositories, a local devDependency keeps TypeScript versions pinned per project and avoids cross-project version drift.

How do I update TypeScript on Ubuntu later?

Run npm install -g typescript@latest and verify with tsc --version. If npm reports permissions errors, switch npm globals to a user-owned prefix and retry the update.

Conclusion

The tsc compiler is on your PATH and compiling .ts files into JavaScript that Node.js can run. From here you can add a tsconfig.json to any project, enable strict mode, and start catching type errors before they reach production. To manage multiple Node.js versions across projects, see install Node.js on Ubuntu. For editor-driven linting and one-click builds, see install Visual Studio Code on Ubuntu.

Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffee Buy me a coffee

Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Leave a Comment

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: