How to Install TypeScript on Ubuntu 26.04 and 24.04

Share

Install TypeScript on Ubuntu 26.04 or 24.04 with npm inside your project, or install it globally for a shared terminal command. TypeScript adds type checking to JavaScript and compiles TypeScript files into JavaScript.

This guide checks Node.js, builds a small project, and explains updates, common errors and removal. If you need help, leave a comment or contact us.

Before you begin
  • Ubuntu 26.04 or 24.04, a terminal, internet access and a regular user account.
  • Node.js and npm are required. Use a supported Node.js LTS release and check the TypeScript package requirements before installing.
  • The example creates a new directory in your home folder. Do not run its initialization steps over an existing project.
  • The commands below use Bash. Project installation does not need sudo.

1. Check Node.js and npm

Check the versions and the executables selected by your shell:

Terminal
node --version
npm --version
command -v node
command -v npm

Both version commands should print a version. If either is missing, follow our Node.js installation guide and return here. It covers a user-managed LTS version and Ubuntu packages. If a version manager is active, its Node.js can take precedence over the system package.

Use a supported Node.js LTS release for new work. Ubuntu 24.04 provides an older Node.js major, so a package meeting a compiler minimum does not necessarily have upstream support. TypeScript requirements can change; check the package metadata before upgrading:

Terminal
npm view typescript version engines

Compare the displayed Node.js requirement with node --version. If your existing project pins TypeScript, check that version instead of assuming the latest is compatible. Network or registry errors here do not prove Node.js is missing.

2. Install TypeScript in a project

A project-local compiler is the recommended choice for applications and teams. The project records its dependency and lockfile, so collaborators can install the same resolved version. Use a new example directory:

Terminal
mkdir "$HOME/typescript-example" && cd "$HOME/typescript-example" && npm init -y

If the directory already exists, choose another name. The command stops if creating or entering it fails. Initialization creates package.json.

Terminal
npm install --save-dev typescript
./node_modules/.bin/tsc --version

The first command records TypeScript as a development dependency and creates or updates package-lock.json. The second runs the compiler installed in this project and should print a version. Run the remaining project commands from this directory. For an existing repository, follow its README and lockfile instead of initializing it again.

Commit the project manifest and lockfile with your code. On another machine, npm ci installs the locked dependencies in a suitable Node environment. It removes and recreates the existing node_modules directory, so use it only inside the intended project.

3. Compile and run your first file

Create a new file named hello.ts in the example directory with your editor. Do not overwrite an existing file. Add:

hello.ts
const message: string = "Hello from TypeScript!";
console.log(message);

Compile the file, then run the generated JavaScript:

Terminal
./node_modules/.bin/tsc hello.ts && node hello.js

You should see Hello from TypeScript!. The compiler checks the type and emits hello.js; Node.js runs the JavaScript. The compiler may overwrite an existing output file, so use a new example directory. If the compiler reports an error, correct it before running the output.

4. Configure the project

Continue in ~/typescript-example, using the hello.ts file you created above. This example is for the new practice project. Do not replace an existing application’s configuration.

Install Node.js type definitions so the compiler recognizes Node globals such as console:

Terminal
cd "$HOME/typescript-example" && npm install --save-dev @types/node

Make sure the practice directory does not already contain tsconfig.json. If it does, use another new practice directory rather than overwriting it. Create tsconfig.json in that directory with your editor and add:

tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "NodeNext",
    "strict": true,
    "noEmitOnError": true,
    "outDir": "dist",
    "types": ["node"]
  },
  "include": ["hello.ts"]
}

strict enables stronger type checks; noEmitOnError prevents new output when errors occur. outDir puts generated files in dist, and include limits this example to hello.ts. NodeNext follows Node.js module rules; ES2020 sets the JavaScript target. types loads the Node definitions installed above.

Check that dist/hello.js does not contain anything you need: a successful build can overwrite it. From the practice directory, compile the configured project and run the output:

Terminal
./node_modules/.bin/tsc && node dist/hello.js

Expected output: Hello from TypeScript!

Earlier, you passed hello.ts directly before creating a configuration. Now run tsc without a filename to load tsconfig.json. With TypeScript 6.0 and later, passing a filename when a configuration is present reports TS5112 unless you explicitly use --ignoreConfig. Older versions ignore the configuration when files are passed.

5. Optional: Install TypeScript globally

A global install provides tsc in your shell for one-off experiments. It is separate from each project dependency. With a user-owned Node version manager such as nvm, install without sudo:

Terminal
npm install --global typescript
tsc --version
command -v tsc

If npm reports EACCES, check npm config get prefix. A system-owned prefix needs a deliberate permissions strategy; follow npm’s permissions guidance or use the project-local method. Do not use sudo with nvm or change ownership of system directories. Global tools installed with nvm belong to the selected Node version.

Update TypeScript

In the project directory, review available updates first:

Terminal
npm outdated typescript

The output compares the installed version with the wanted and latest versions. No output can mean no outdated dependency was found. Check errors separately if the command cannot reach the registry.

Check the release notes and your project’s compatibility before upgrading. @latest can cross a major version and introduce breaking changes. When you are ready to update this project, run:

Terminal
npm install --save-dev typescript@latest

Review changes to the manifest and lockfile, then verify the compiler and build the configured project:

Terminal
./node_modules/.bin/tsc --version
./node_modules/.bin/tsc

Run your project’s tests as well. If it requires a particular major version, select that version instead of latest.

For a separate user-owned global installation, use the same Node version and account used to install it:

Terminal
npm install --global typescript@latest
tsc --version

APT updates Ubuntu packages; it does not update TypeScript installed by npm.

Troubleshooting

1. tsc: command not found
A local install does not normally add tsc to your interactive shell PATH. From the project directory use ./node_modules/.bin/tsc --version. If the file is absent, check the installation output and run npm install in the correct project. For a global install, inspect the npm prefix and your PATH. Reopen the terminal if you changed shell configuration.
2. The wrong compiler version runs
Run type -a tsc and compare it with ./node_modules/.bin/tsc --version inside the project. A global compiler and project compiler can differ. npm scripts normally resolve project binaries first. Switching nvm versions can also change global tools.
3. TS5112 or unexpected output
TypeScript 6.0 and later reports TS5112 when file arguments would bypass an existing configuration. Run the compiler without a file argument to read the project settings. Check outDir and compiler messages before looking for the output.
4. A type error appears
Read the filename and line number in the compiler output. For a simple test, change the example to const message: string = 123; and compile again. TypeScript should reject the number because the variable is declared as a string. Restore the original string and compile again. Depending on configuration, TypeScript can still emit JavaScript when it reports errors; do not treat an output file alone as proof of success.
5. Installation or execution fails
Check node --version, the package engine requirement, your architecture and the full error. Check registry connectivity with npm ping. Do not assume all npm packages support every processor architecture; consult the package metadata and your project requirements.

Uninstall TypeScript

To remove the dependency from this project, run the following inside the project directory. It updates the project manifest and lockfile and can affect builds that need TypeScript:

Terminal
npm uninstall --save-dev typescript

For a user-owned global installation, use the same Node version and account that installed it:

Terminal
npm uninstall --global typescript
hash -r
type -a tsc

If another compiler remains on PATH, the final command can still show it. A missing command is expected if no other installation exists. These steps do not remove Node.js or your source files. Remove a practice project only after backing up anything you want to keep.

Helpful resources

See the official TypeScript installation guide and TSConfig reference for current options and compatibility details.

Frequently Asked Questions

Do I need Node.js to install TypeScript?

The npm compiler workflow in this guide requires Node.js and npm. The JavaScript produced can run in a compatible browser or runtime.

Should I install TypeScript locally or globally?

Use a local development dependency for a project so its compiler version can be shared. A global installation is convenient for experiments.

Does TypeScript run my application?

The compiler checks TypeScript and can produce JavaScript. Run the resulting JavaScript with an appropriate runtime or browser.

Can Node.js run TypeScript files directly?

Yes. Supported modern Node.js versions can run TypeScript files containing supported syntax using type stripping. This does not type-check the code or use tsconfig.json. Use the compiler when you need type checking and JavaScript output.

Does removing TypeScript remove Node.js?

No. The npm uninstall commands remove the selected TypeScript package, not Node.js or your source files.

Related guides: Visual Studio Code on Ubuntu | Install React on Ubuntu | Install Bun on Ubuntu.