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.
1. Check Node.js and npm
Check the versions and the executables selected by your shell:
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:
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:
If the directory already exists, choose another name. The command stops if creating or entering it fails. Initialization creates package.json.
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:
Compile the file, then run the generated JavaScript:
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:
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:
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:
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:
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:
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:
Review changes to the manifest and lockfile, then verify the compiler and build the configured project:
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:
APT updates Ubuntu packages; it does not update TypeScript installed by npm.
Troubleshooting
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:
For a user-owned global installation, use the same Node version and account that installed it:
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.
