How to Install TypeScript on Linux (A Step-by-Step Guide)

Key Takeaways

  • Prerequisite: TypeScript installation on Linux requires Node.js and its package manager, npm, to be installed first.
  • Core Command: The primary command to install TypeScript globally on your system is $ npm install -g typescript.
  • Verification: After installation, you can confirm it was successful by running the command $ tsc -v, which displays the installed compiler version.
  • Next Steps: Once installed, you can start writing code in .ts files and compile them into standard JavaScript using the tsc command (e.g., $ tsc yourfile.ts).

What is TypeScript?

TypeScript is a powerful, open-source programming language developed and maintained by Microsoft. It acts as a strict syntactical superset of JavaScript, meaning any valid JavaScript code is also valid TypeScript code. Its main advantage is adding optional static typing, which helps developers catch errors early in the development process, long before the code is run. For anyone looking to build robust, scalable applications, understanding what is TypeScript is a crucial first step.

Why Do I Need Node.js to Install TypeScript?

You need Node.js because the TypeScript compiler, the tool that converts your TypeScript code (.ts) into browser-readable JavaScript (.js), is distributed as a package through the Node Package Manager (npm). npm is bundled with every installation of Node.js. Therefore, installing Node.js is the essential first step to getting npm, which in turn allows you to install TypeScript.

Step 1: Install Node.js

  • Open Terminal: Launch your Linux distribution’s Terminal.
  • Update Package Lists (if needed): For Debian-based systems (like Ubuntu), run: Bashsudo apt update For Red Hat-based systems (like Fedora), run: Bashsudo dnf upgrade
  • Install Node.js:

Debian-based:

Bash
sudo apt install nodejs

Red Hat-based:

Bash
sudo dnf install nodejs
  • Other Distributions: Use your distribution’s package manager (e.g., pacman for Arch Linux, zypper for openSUSE) to install the nodejs package.
  • Verify Node.js Installation:
    • In Terminal, type node -v and press Enter. This should display the installed Node.js version.

Step 2: Install TypeScript

  • Open Terminal: If you close it, open a new Terminal window.
  • Install TypeScript Globally: Run the following command:

npm install -g typescript 

  • The -g flag installs TypeScript globally, making it accessible from any location on your system.
  • Verify TypeScript Installation:
    • In Terminal, type
Bash
tsc -v
  • and press Enter to display the installed TypeScript version.

Step 3: (Optional) Update TypeScript

To update to a newer version of TypeScript in the future, run:

Bash
npm update -g typescript

That’s it! You have successfully installed TypeScript on your Linux machine. You are now ready to start developing with TypeScript!

Elsewhere On TurboGeek:  Learn About Kubernetes (K8s) Objects

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »