Alright, let’s get you set up to actually use TypeScript. We’re going to do this the right way, which means I’m going to talk you out of installing it globally almost immediately. Stick with me.

The first thing you need is Node.js and its trusty sidekick, npm (or its speedier, modern cousin, pnpm or yarn). If you don’t have Node.js on your machine, go grab the LTS version from the official website. I’ll wait. Don’t worry, this isn’t the kind of book where I make you feel bad for not having things installed beforehand. We’ve all been there.

The Global Install: A Quick Fix You’ll Quickly Outgrow

The most obvious, Google-able way to install TypeScript is globally. It makes the tsc (TypeScript Compiler) command available anywhere on your system. It’s simple, and for a quick one-off script, it’s fine.

npm install -g typescript

Verify it worked by asking TypeScript its version. It’s polite.

tsc --version

So why am I already giving this approach the side-eye? Because global dependencies are a recipe for “but it works on my machine” disasters. Imagine you start Project A using TypeScript v5.3. A year from now, you start slick new Project B and globally upgrade to TypeScript v5.9. You go back to fix a tiny bug in Project A, run tsc, and suddenly it’s raining type errors because the new, stricter compiler is now applying its rules to your old code. The project-specific tsconfig.json file (which we’ll get to) helps, but the core compiler behavior can still change. You’ve just created a headache for Future You, and Future You hates Present You for that.

The Per-Project Install: The Professional’s Choice

This is the way. You install TypeScript as a development dependency within each individual project. This locks the project to a specific TypeScript version, guaranteed. Your coworker (or you on a different machine) clones the repo, runs npm install, and gets the exact same toolchain. It’s beautiful.

Navigate to your project’s root directory and run:

# Using npm
npm install --save-dev typescript

# Or if you're cool and using pnpm
pnpm add --dev typescript

This does not make tsc available as a global command. If you just type tsc in your terminal now, it’ll probably complain. This is a feature, not a bug.

So How Do You Run the Compiler?

“Great,” you’re thinking, “I’ve installed a tool I can’t run. Thanks a lot.” Calm down. npm solves this for you. When you install a package locally, its binaries land in ./node_modules/.bin/. You have three ways to access it:

  1. The Verbose Path: You can run it by specifying the full path.

    ./node_modules/.bin/tsc --version
    

    This is… fine. I guess. If you enjoy typing.

  2. npx: The Hero We Deserve: npx is a brilliant little tool that comes with npm. It automatically looks for a command in the local node_modules before checking your global installs. This is your new best friend.

    npx tsc --version
    

    It’s clean, it’s explicit, and it uses the project’s specific version. Use this for one-off commands.

  3. npm Scripts: The Real Power Move: This is how you’ll actually work day-to-day. You define scripts in your package.json file. npm automatically adds ./node_modules/.bin/ to the path when executing these scripts, so you can just use tsc directly.

Open your package.json and add a scripts section if it doesn’t exist:

{
  "name": "my-awesome-project",
  "version": "1.0.0",
  "devDependencies": {
    "typescript": "^5.3.0"
  },
  "scripts": {
    "build": "tsc",
    "dev": "tsc --watch"
  }
}

Now, instead of remembering arcane npx commands, you just run:

npm run build   # Compiles your project once
npm run dev     # Runs the compiler in watch mode, recompiling on every save

This is infinitely better. You can add complex flags and arguments in one central, documented place instead of expecting everyone on your team to memorize them. You’ll also use this later to hook TypeScript into your bundler and other tools.

Why –save-dev? What’s the Difference?

You might have noticed we used --save-dev (or -D). This tells npm to add TypeScript to the devDependencies list in your package.json, not the regular dependencies.

This is a crucial distinction. TypeScript is a development tool. Your finished, compiled JavaScript code doesn’t need TypeScript to run; it just needs Node.js or a browser. When you deploy your application to production, you’ll install only the dependencies (the stuff your running program needs), skipping the devDependencies (the stuff you need to build the program). It keeps things lean and mean. The only time you’d add it to regular dependencies is if you were writing a library and publishing type definitions directly—a topic for another day.

So, to recap: install locally per-project, use npx for quick checks, and use npm scripts for everything else. You’ve now avoided the first major pitfall most people stumble into. See? I’ve got your back.