Course contentsShow
← TypeScript
Lesson 41 of 1,7962. Setup and ToolingFree lesson

Installing TypeScript Globally vs Locally

Learn the difference between global and project-local TypeScript installations and when to use each approach.

Installing TypeScript Globally vs Locally

What you'll learn: The difference between installing TypeScript on your entire system versus inside a single project, and when each approach makes sense.

When you install TypeScript, you have two options: global (available everywhere on your machine) or local (only within a specific project folder).

Global Installation

Installing TypeScript globally means you're putting it in a central location on your computer, accessible from any directory. You do this once:

npm install -g typescript

Think of this like installing a tool in your garage—it's always there when you need it, no matter which project you're working on.

When to use global: Great for quick experiments, learning, or using TypeScript's command-line tools (tsc) from anywhere. However, this can cause problems when different projects need different TypeScript versions.

Local Installation

Installing TypeScript locally means adding it to a specific project's dependencies:

npm install --save-dev typescript

This approach is like having a toolbox for each project—every project carries its own version of TypeScript, ensuring consistency.

When to use local: This is the recommended approach for real projects. It guarantees everyone on your team uses the same TypeScript version, prevents version conflicts between projects, and makes your project self-contained. If someone clones your repository, they get the exact TypeScript version your code was written for.

The Practical Difference

With a global install, you run tsc directly. With a local install, you typically run it through npm scripts in your package.json or use npx tsc to execute the local version.

Key Takeaway: Install TypeScript locally for projects you share or maintain long-term, and optionally install it globally for convenience when learning or experimenting. Most professional projects use local installations to avoid version conflicts.