我通过 apt 安装了 tsc,现在我不知道如何删除或更新它

I installed tsc through apt and now I don't know how to remove or update it

所以我在我的服务器上缺少打字稿并尝试 运行 tsc 并且我收到消息“不识别 tsc 命令,你是想使用 apt install tsc 安装它吗?”或类似的东西。没想那么多,我运行命令。通常我会使用 npm i -g typescript 安装它。它确实安装了打字稿,但版本错误(2.7.something,我需要 4.0+)和 运行ing tsc -v returns 版本,但 apt-get update 不更新它,当我 运行 dpkg --list, apt-get remove/apt remove tsc/typescript 什么都不做(找不到包 tsc/typescript 时,它没有出现在列表中) 但 tsc 命令确实有效并尝试编译我的文件但抛出错误类型错误,因为它是旧版本。 npm uninstall/remove -g tsc/typescript 也什么都不做。

如何删除这个tsc并通过npm正常安装typescript?

编辑:我还应该注意,它没有安装在本地的某个文件夹中。我在服务器上的任何位置都遇到相同的行为。

这是我尝试过的一些命令和得到的结果的屏幕截图:

(注意:可在 chat discussion 中找到更多信息)

TL;DR: 这可能是因为您安装了 node-typescript package via apt-get at some point, which only provides v2.7.2 as the latest version of TypeScript for your current Ubuntu version (which you've specified is 18.04 LTS, or Bionic Beaver).

这意味着您要么必须:

  • 切换到 Ubuntu 的较新版本(例如最新的稳定版本,20.04 - Focal Fossa) which offers v3.8.3 作为当前版本,或
  • 卸载 node-typescript 包(带有 sudo apt-get remove node-typescript),而是通过 NPM 安装 TypeScript。这意味着 TypeScript 更新现在与 Ubuntu 版本分离。