How to Install TypeScript on Ubuntu 26.04, 24.04 and 22.04

Install TypeScript on Ubuntu 26.04, 24.04 and 22.04 with npm. Covers Node.js setup, global tsc, and troubleshooting.

UpdatedPublished AuthorJoshua JamesRead time5 minGuide typeUbuntu

TypeScript pays off before code ever reaches production: the compiler catches type mismatches, missing properties, and unsafe refactors while you still have the file open. To install TypeScript on Ubuntu, set up a supported Node.js and npm runtime, install the npm package that provides tsc, then compile a small file to confirm the toolchain works.

Current TypeScript from npm provides tsc and tsserver and requires Node.js 14.17 or newer. Ubuntu 26.04 and 24.04 can use their repository Node.js packages for this workflow, while Ubuntu 22.04 needs a newer Node.js path such as NodeSource or NVM before installing the latest compiler.

Install TypeScript on Ubuntu

Refresh package metadata first so Ubuntu sees the current repository candidates before you check or install Node.js.

sudo apt update

These commands use sudo for tasks that need root privileges. If your account is not in the sudoers group, follow the guide to add and manage sudo users on Ubuntu.

Check Node.js Support for TypeScript

TypeScript installs through npm, so the active Node.js version matters more than the Ubuntu release number. Verify the runtime already available in your shell:

node --version
npm --version

If both commands return versions and Node.js is 14.17 or newer, continue. The npm package metadata for current TypeScript requires node >=14.17, and Ubuntu repository candidates fall into these version lines:

Ubuntu ReleaseRepository Node.js CandidateTypeScript Status
Ubuntu 26.04 (Resolute)22.22.xWorks with current TypeScript
Ubuntu 24.04 (Noble)18.19.xWorks with current TypeScript
Ubuntu 22.04 (Jammy)12.22.xToo old for current TypeScript

If Node.js or npm is missing on Ubuntu 26.04 or 24.04, install the repository packages:

sudo apt install nodejs npm

The nodejs and npm packages come from Ubuntu’s Universe component. Minimal or customized systems that cannot locate them should enable Universe first; the Ubuntu Universe and Multiverse guide explains that repository setup.

On Ubuntu 22.04, skip the default repository package for current TypeScript work. Install a supported Node.js release first with NodeSource or NVM on Ubuntu, then return to the TypeScript steps below.

Choose Global or Project-Local TypeScript

TypeScript can be installed globally for quick terminal access or locally inside a project so the compiler version stays pinned with the repository.

Install ScopeCommand PatternBest For
Global compilersudo npm install -g typescriptOne shared tsc command available from any directory
Project-local compilernpm install --save-dev typescriptPinned compiler versions for teams, CI, and production repositories

Use the global method when you want a fast system-wide compiler check. Use the project-local method when a repository should control its own TypeScript version through package.json and package-lock.json.

Install the Global tsc Compiler on Ubuntu

Install the current TypeScript package globally when you want tsc available throughout the system:

sudo npm install -g typescript

If you installed Node.js with NVM, omit sudo and run npm install -g typescript inside the active NVM shell. NVM installs packages under your home directory, so mixing it with sudo npm can put global tools in the wrong prefix.

Verify the compiler version:

tsc --version

The exact point release changes as npm publishes updates. Current TypeScript 6 output follows this format:

Version 6.x.x

Confirm your shell resolves the compiler path:

command -v tsc

Common global installs return:

/usr/local/bin/tsc

Install TypeScript Locally in a Project on Ubuntu

For real application repositories, install TypeScript as a development dependency. This keeps the compiler version with the project instead of depending on whichever global version happens to be installed.

mkdir ts-test-project
cd ts-test-project
npm init -y
npm install --save-dev typescript
npx tsc --init

The initialization step creates a project config file. Confirm it exists before compiling through the local project setup:

ls tsconfig.json
tsconfig.json

Check the local compiler with npx, which runs binaries from the project dependency tree:

npx tsc --version

Current TypeScript 6 output follows this format:

Version 6.x.x

Run a TypeScript Compile Test on Ubuntu

Compile one small file to confirm the TypeScript compiler and Node.js runtime work together. Create the test file from the project directory you created above, or from any temporary directory if you installed TypeScript globally:

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

If you installed TypeScript globally, compile and run the file with tsc:

tsc hello.ts
node hello.js

If you installed TypeScript as a project dependency, compile through npx without naming the file. The earlier npx tsc --init command created tsconfig.json, so this form tells TypeScript to use the project config:

npx tsc
node hello.js

The compiler turns hello.ts into hello.js by removing the : string type annotation and writing plain JavaScript that Node.js can run.

Expected output:

Hello, World!

This compile test is only a quick Ubuntu toolchain check. For language syntax, interfaces, generics, and project migration examples, continue with the official TypeScript Handbook after the install is verified.

The tsconfig.json file controls the JavaScript target, module behavior, strict type checking, and output paths. For stricter checks and custom build targets, review the official TypeScript TSConfig reference.

Update TypeScript on Ubuntu

Update a global TypeScript install through npm, then verify the compiler version again:

sudo npm install -g typescript@latest
tsc --version

If you use NVM, run the same npm update without sudo inside the active NVM shell:

npm install -g typescript@latest
tsc --version

For a project-local install, update the dependency from the project directory:

npm install --save-dev typescript@latest
npx tsc --version

Troubleshoot TypeScript on Ubuntu

Fix tsc Command Not Found on Ubuntu

If the shell cannot find tsc, npm may have installed the global binary outside your current PATH.

Common error:

bash: tsc: command not found

Check npm’s global prefix and the expected binary path:

npm config get prefix
ls "$(npm config get prefix)/bin/tsc"

Typical output for a system-wide npm install is:

/usr/local
/usr/local/bin/tsc

If the binary exists but your shell cannot resolve it, update an article-owned PATH line in ~/.bashrc. The marker lets you rerun the command later if npm’s global prefix changes:

NPM_BIN="$(npm config get prefix)/bin"
touch "$HOME/.bashrc"
sed -i '/# LinuxCapable npm global path$/d' "$HOME/.bashrc"
printf 'export PATH="%s:$PATH" # LinuxCapable npm global path\n' "$NPM_BIN" >> "$HOME/.bashrc"
. "$HOME/.bashrc"
command -v tsc

The final command should print the compiler path, such as:

/usr/local/bin/tsc

Fix TS5112 When tsconfig.json Exists

Current TypeScript reports TS5112 if you pass a file name while a project tsconfig.json is present:

error TS5112: tsconfig.json is present but will not be loaded if files are specified on commandline.

From a project-local install, run the compiler without the file argument so it reads tsconfig.json:

npx tsc

If you installed TypeScript globally and are compiling inside a project that already has tsconfig.json, use tsc without the file argument for the same reason.

Fix npm EACCES Permission Errors

Permission errors usually appear when you run global npm installs without sudo while npm is using a root-owned prefix such as /usr/local.

Common error:

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

For per-user global tools, move npm’s global prefix into your home directory and install TypeScript without sudo:

mkdir -p "$HOME/.npm-global"
npm config set prefix "$HOME/.npm-global"
grep -qxF 'export PATH="$HOME/.npm-global/bin:$PATH"' "$HOME/.bashrc" || printf '%s\n' 'export PATH="$HOME/.npm-global/bin:$PATH"' >> "$HOME/.bashrc"
. "$HOME/.bashrc"
npm install -g typescript
tsc --version

For project repositories, prefer npm install --save-dev typescript instead of changing the global prefix. The local dependency avoids global permissions entirely and keeps the compiler version with the project.

Fix TypeScript Errors from Old Node.js on Ubuntu 22.04

Ubuntu 22.04 repository packages currently provide Node.js 12.22.x, which is below the current TypeScript npm package requirement.

Check the active runtime:

node --version

If Ubuntu 22.04 is still using its repository package, the output resembles:

v12.22.9

Install a supported Node.js LTS or current release with NodeSource or NVM on Ubuntu, open a new shell if that method changes your profile, then rerun the TypeScript install command.

Remove TypeScript from Ubuntu

Remove the global compiler with npm first:

sudo npm uninstall -g typescript
hash -r
command -v tsc || echo "tsc not found"

A removed global compiler returns:

tsc not found

If you installed TypeScript with NVM, omit sudo:

npm uninstall -g typescript
hash -r
command -v tsc || echo "tsc not found"

For a project-local install, remove the development dependency from that repository:

npm uninstall --save-dev typescript

If you installed Node.js and npm from Ubuntu repositories, remove them only when no other JavaScript tooling on the system depends on them:

sudo apt remove nodejs npm
dpkg -l nodejs npm 2>/dev/null | grep '^ii' || echo "nodejs and npm are not installed"

Review dependency cleanup separately before confirming a wider package removal. The Ubuntu package removal guide explains how to inspect APT’s removal and autoremove previews safely.

Conclusion

The tsc compiler is available on Ubuntu through npm, either as a global command or as a project-pinned development dependency. The quick compile test confirms that TypeScript can produce JavaScript for Node.js to run. For broader runtime management, install Node.js on Ubuntu; for editor integration, install Visual Studio Code on Ubuntu.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
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 coffeeBuy 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 in published comments:

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

Got a Question or Feedback?

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

Let us know you are human: