274

Currently I have TypeScript 1.0.3.0 version installed on my machine.
I want to update it to latest one i.e. 2.0.

How to do this with npm?

Kyll
  • 7,036
  • 7
  • 41
  • 64
blueMoon
  • 2,831
  • 2
  • 13
  • 10

11 Answers11

465

Try npm install -g typescript@latest. You can also use npm update instead of install, without the latest modifier.

eavidan
  • 5,324
  • 1
  • 13
  • 16
  • I have tried it on windows command prompt. I'm using Microsoft's visual studio code. – blueMoon Sep 24 '16 at 14:44
  • 12
    If you type "npm list -g", what version of TypeScript appears? – eavidan Sep 24 '16 at 14:47
  • 3
    Oops! I'm using latest one only 2.1.0. I was mistakenly considered `tsc -v ` as `TypeScript` version as it was showing 1.0 – blueMoon Sep 24 '16 at 14:52
  • 10
    Open Cmd and do 'where tsc' , which shows the list of typescripts in the path then you can manually delete the typescript paths outside of nodejs. This trick worked for me after hours frustration while updating to typescript 2.2.2. – EvilInside Apr 06 '17 at 18:07
  • My typescript is updated but I still can't generate "tsc --init" – Carl Sare May 29 '18 at 01:38
  • @EvilInside This finally got it working for me too! You should consider editing the answer to include your comment. – LCIII Jul 22 '19 at 18:45
  • npm update -g typescript doens't work instead, just for pick up note – Renan Duarte Aug 21 '20 at 14:37
  • In linux you still need to check if the executable /usr/bin/tsc is the same as /home//.nvm/versions/node//bin/tsc (or whatelse it is the npm global destination). Sometimes 'npm install -g' does not update the executable (tsc) in /usr/bin – Jeff Pal Sep 25 '21 at 03:05
120

Open command prompt (cmd.exe/git bash)

Recommended:

npm install -g typescript@latest

or

yarn global add typescript@latest  // if you use yarn package manager

This will install the latest typescript version if not already installed, otherwise it will update the current installation to the latest version.

And then verify which version is installed:

tsc -v

enter image description here


If you have typescript already installed you could also use the following command to update to latest version, but as commentators have reported and I confirm it that the following command does not update to latest (as of now [ Feb 10 '17])!

npm update -g typescript@latest
Legends
  • 21,202
  • 16
  • 97
  • 123
  • tsc -v command not recognized, tried npm ls typescript module-ui@0.1.0 /Users/.../Repo/module-ui └── typescript@3.9.7 – user1769790 Aug 04 '20 at 18:39
37

If you are on Windows and have Visual Studio installed you might have something in your PATH that is pointing to an old version of TypeScript. I found that removing the folder "C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\" from my PATH (or deleting/renaming this folder) will allow the more recent npm globally installed TypeScript version of tsc to work.

Veener
  • 4,771
  • 2
  • 29
  • 37
12

You should be able to do this by simply typing npm install -g typescript@2.0. If this does not work, I am beginning to wonder what version of node and npm you are on. Try node -v and npm -v to find these out. You should be on node >4.5 and npm >3

Andrew Reid
  • 121
  • 2
  • If you have a older version of npm, use this: http://stackoverflow.com/questions/18412129/how-do-i-update-node-and-npm-on-windows – johnander11 Apr 20 '17 at 08:54
4

For npm: you can run:

npm update -g typescript

By default, it will install latest version.

For yarn, you can run:

yarn upgrade typescript

Or you can remove the orginal version, run yarn global remove typescript, and then execute yarn global add typescript, by default it will also install the latest version of typescript.

more details, you can read yarn docs.

Community
  • 1
  • 1
Little Roys
  • 5,383
  • 3
  • 30
  • 28
3

My solution to this error was to update the typescript version with this command:

npm install -g typescript@latest as I was using Windows. However on Mac this can also be doable by sudo npm install -g typescript@latest

gildniy
  • 3,528
  • 1
  • 33
  • 23
2

Just use the command # npm update -g typescript
For update all global installed module, Use this command# npm update -g

Pascal Tovohery
  • 888
  • 7
  • 19
2

Use the command where in prompt to find the current executable in path

C:\> where tsc
C:\Users\user\AppData\Roaming\npm\tsc
C:\Users\user\AppData\Roaming\npm\tsc.cmd
Muhammed Moussa
  • 4,589
  • 33
  • 27
impactro
  • 564
  • 4
  • 7
2

Try

sudo apt-get update

Next install the latest version of typescript globally with

npm install -g typescript@latest

After it's done, type

tsc -v

to see the latest version of typescript installed in your system.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Ahad
  • 49
  • 1
  • 6
2

If your system already installs typescript globally you just need to update the typescript version.

Make sure to check your typescript version first.

tsc -v 

or

tsc

tsc command gives you more details.

If everything is configured properly and there are no issues. You only need to upgrade your typescript version at this point.

npm update -g typescript
Omor Faruk
  • 57
  • 8
1

If you are using Windows with very old NodeJS, then uninstall previous NodeJs and NVM (Node Version Manager) in Control Panel (Win7) or Settings/Apps (Win10) if exists. Make sure that they are removed from the PATH.

Reinstall NodeJS: https://nodejs.org/en/download It will install NPM as well.

Install TypeScript globally:

npm install -g typescript

Verify installation:

tsc -v
Donato Szilagyi
  • 4,279
  • 4
  • 36
  • 53