Linux中安装 Visual Studio Code 详解

一起来学习如何在 Linux 发行版中安装 Visual Studio Code。Visual Studio Code 是基于 Electron 优化代码后的编辑器,后者是基于 Chromium 的一款软件,用于为桌面系统发布 io.js 应用。Visual Studio Code 是微软开发的支持包括 Linux 在内的全平台代码编辑器和文本编辑器。它是免费软件但不开源,在专有软件许可条款下发布。它是可以用于我们日常使用的超级强大和快速的代码编辑器。 Visual Studio Code 有很多很酷的功能,例如导航、智能感知支持、语法高亮、括号匹配、自动补全、代码片段、支持自定义键盘绑定、并且支持多种语言,例如 Python、C++、Jade、PHP、XML、Batch、F#、DockerFile、Coffee Script、Java、HandleBars、 R、 Objective-C、 PowerShell、 Luna、 Visual Basic、 .Net、 Asp.Net、 C#、 JSON、 Node.js、 Javascript、 HTML、 CSS、 Less、 Sass 和 Markdown。Visual Studio Code 集成了包管理器、库、构建,以及其它通用任务,以加速日常的工作流。Visual Studio Code 中最受欢迎的是它的调试功能,它包括流式支持 Node.js 的预览调试。

注意:请注意 Visual Studio Code 只支持 64 位的 Linux 发行版。

下面是在所有 Linux 发行版中安装 Visual Studio Code 的几个简单步骤。

1. 下载 Visual Studio Code 软件包

首先,我们要从微软服务器中下载 64 位 Linux 操作系统的 Visual Studio Code 安装包,链接是 http://go.microsoft.com/fwlink/?LinkID=534108。这里我们使用 wget 下载并保存到 tmp/VSCODE 目录。

  1. <span class="com"># mkdir /tmp/vscode; cd /tmp/vscode/</span>
  2. <span class="com"># wget https://az764295.vo.msecnd.net/public/0.3.0/VSCode-linux-x64.zip</span>
  3.  
  4. <span class="pun">--</span><span class="lit">2015</span><span class="pun">-</span><span class="lit">06</span><span class="pun">-</span><span class="lit">24</span><span class="lit">06</span><span class="pun">:</span><span class="lit">02</span><span class="pun">:</span><span class="lit">54</span><span class="pun">--</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//az764295.vo.msecnd.net/public/0.3.0/VSCode-linux-x64.zip</span>
  5. <span class="typ">Resolving</span><span class="pln"> az764295</span><span class="pun">.</span><span class="pln">vo</span><span class="pun">.</span><span class="pln">msecnd</span><span class="pun">.</span><span class="pln">net </span><span class="pun">(</span><span class="pln">az764295</span><span class="pun">.</span><span class="pln">vo</span><span class="pun">.</span><span class="pln">msecnd</span><span class="pun">.</span><span class="pln">net</span><span class="pun">)...</span><span class="lit">93.184</span><span class="pun">.</span><span class="lit">215.200</span><span class="pun">,</span><span class="lit">2606</span><span class="pun">:</span><span class="lit">2800</span><span class="pun">:</span><span class="lit">11f</span><span class="pun">:</span><span class="lit">179a</span><span class="pun">:</span><span class="lit">1972</span><span class="pun">:</span><span class="lit">2405</span><span class="pun">:</span><span class="lit">35b</span><span class="pun">:</span><span class="lit">459</span>
  6. <span class="typ">Connecting</span><span class="pln"> to az764295</span><span class="pun">.</span><span class="pln">vo</span><span class="pun">.</span><span class="pln">msecnd</span><span class="pun">.</span><span class="pln">net </span><span class="pun">(</span><span class="pln">az764295</span><span class="pun">.</span><span class="pln">vo</span><span class="pun">.</span><span class="pln">msecnd</span><span class="pun">.</span><span class="pln">net</span><span class="pun">)|</span><span class="lit">93.184</span><span class="pun">.</span><span class="lit">215.200</span><span class="pun">|:</span><span class="lit">443.</span><span class="pun">..</span><span class="pln"> connected</span><span class="pun">.</span>
  7. <span class="pln">HTTP request sent</span><span class="pun">,</span><span class="pln"> awaiting response</span><span class="pun">...</span><span class="lit">200</span><span class="pln"> OK</span>
  8. <span class="typ">Length</span><span class="pun">:</span><span class="lit">64992671</span><span class="pun">(</span><span class="lit">62M</span><span class="pun">)</span><span class="pun">[</span><span class="pln">application</span><span class="pun">/</span><span class="pln">octet</span><span class="pun">-</span><span class="pln">stream</span><span class="pun">]</span>
  9. <span class="typ">Saving</span><span class="pln"> to</span><span class="pun">:</span><span class="pun">‘</span><span class="typ">VSCode</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x64</span><span class="pun">.</span><span class="pln">zip</span><span class="pun">’</span>
  10. <span class="lit">100</span><span class="pun">%[================================================>]</span><span class="lit">64</span><span class="pun">,</span><span class="lit">992</span><span class="pun">,</span><span class="lit">671</span><span class="lit">14.9MB</span><span class="pun">/</span><span class="pln">s </span><span class="kwd">in</span><span class="lit">4.1s</span>
  11. <span class="lit">2015</span><span class="pun">-</span><span class="lit">06</span><span class="pun">-</span><span class="lit">24</span><span class="lit">06</span><span class="pun">:</span><span class="lit">02</span><span class="pun">:</span><span class="lit">58</span><span class="pun">(</span><span class="lit">15.0</span><span class="pln"> MB</span><span class="pun">/</span><span class="pln">s</span><span class="pun">)</span><span class="pun">-</span><span class="pun">‘</span><span class="typ">VSCode</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x64</span><span class="pun">.</span><span class="pln">zip</span><span class="pun">’</span><span class="pln"> saved </span><span class="pun">[</span><span class="lit">64992671</span><span class="pun">/</span><span class="lit">64992671</span><span class="pun">]</span>

2. 提取软件包

现在,下载好 Visual Studio Code 的 zip 压缩包之后,我们打算使用 unzip 命令解压它。我们要在终端或者控制台中运行以下命令。

  1. <span class="com"># unzip /tmp/vscode/VSCode-linux-x64.zip -d /opt/</span>

注意:如果我们还没有安装 unzip,我们首先需要通过软件包管理器安装它。如果你运行的是 Ubuntu,使用 apt-get,如果运行的是 Fedora、CentOS、可以用 dnf 或 yum 安装它。

3. 运行 Visual Studio Code

展开软件包之后,我们可以直接运行一个名为 Code 的文件启动 Visual Studio Code。

  1. <span class="com"># sudo chmod +x /opt/VSCode-linux-x64/Code</span>
  2. <span class="com"># sudo /opt/VSCode-linux-x64/Code</span>

如果我们想通过终端在任何地方启动 Code,我们就需要创建 /opt/vscode/Code 的一个链接 /usr/local/bin/code。

  1. <span class="com"># ln -s /opt/VSCode-linux-x64/Code /usr/local/bin/code</span>

现在,我们就可以在终端中运行以下命令启动 Visual Studio Code 了。

  1. <span class="com"># code .</span>

4. 创建桌面启动

下一步,成功展开 Visual Studio Code 软件包之后,我们打算创建桌面启动程序,使得根据不同桌面环境能够从启动器、菜单、桌面启动它。首先我们要复制一个图标文件到 /usr/share/icons/ 目录。

  1. <span class="com"># cp /opt/VSCode-linux-x64/resources/app/vso.png /usr/share/icons/</span>

然后,我们创建一个桌面启动程序,文件扩展名为 .desktop。这里我们使用喜欢的文本编辑器在 /tmp/VSCODE/ 目录中创建名为 visualstudiocode.desktop 的文件。

  1. <span class="com"># vi /tmp/vscode/visualstudiocode.desktop</span>

然后,粘贴下面的行到那个文件中。

  1. <span class="pun">[</span><span class="typ">Desktop</span><span class="typ">Entry</span><span class="pun">]</span>
  2. <span class="typ">Name</span><span class="pun">=</span><span class="typ">Visual</span><span class="typ">Studio</span><span class="typ">Code</span>
  3. <span class="typ">Comment</span><span class="pun">=</span><span class="typ">Multi</span><span class="pun">-</span><span class="pln">platform code editor </span><span class="kwd">for</span><span class="typ">Linux</span>
  4. <span class="typ">Exec</span><span class="pun">=</span><span class="str">/opt/</span><span class="typ">VSCode</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x64</span><span class="pun">/</span><span class="typ">Code</span>
  5. <span class="typ">Icon</span><span class="pun">=</span><span class="str">/usr/</span><span class="pln">share</span><span class="pun">/</span><span class="pln">icons</span><span class="pun">/</span><span class="pln">vso</span><span class="pun">.</span><span class="pln">png</span>
  6. <span class="typ">Type</span><span class="pun">=</span><span class="typ">Application</span>
  7. <span class="typ">StartupNotify</span><span class="pun">=</span><span class="kwd">true</span>
  8. <span class="typ">Categories</span><span class="pun">=</span><span class="typ">TextEditor</span><span class="pun">;</span><span class="typ">Development</span><span class="pun">;</span><span class="typ">Utility</span><span class="pun">;</span>
  9. <span class="typ">MimeType</span><span class="pun">=</span><span class="pln">text</span><span class="pun">/</span><span class="pln">plain</span><span class="pun">;</span>

创建完桌面文件之后,我们会复制这个桌面文件到 /usr/share/applications/ 目录,这样启动器和菜单中就可以单击启动 Visual Studio Code 了。

  1. <span class="com"># cp /tmp/vscode/visualstudiocode.desktop /usr/share/applications/</span>

完成之后,我们可以在启动器或者菜单中启动它。

Linux中安装 Visual Studio Code 详解

Visual Studio Code

在 Ubuntu 中 Visual Studio Code

要在 Ubuntu 14.04/14.10/15.04 Linux 发行版中安装 Visual Studio Code,我们可以使用 Ubuntu Make 0.7。这是在 ubuntu 中安装 code 最简单的方法,因为我们只需要执行几个命令。首先,我们要在我们的 ubuntu linux 发行版中安装 Ubuntu Make 0.7。要安装它,首先要为它添加 PPA。可以通过运行下面命令完成。

  1. <span class="com"># add-apt-repository ppa:ubuntu-desktop/ubuntu-make</span>
  2.  
  3. <span class="typ">This</span><span class="pln"> ppa proposes </span><span class="kwd">package</span><span class="pln"> backport of </span><span class="typ">Ubuntu</span><span class="pln"> make </span><span class="kwd">for</span><span class="pln"> supported releases</span><span class="pun">.</span>
  4. <span class="typ">More</span><span class="pln"> info</span><span class="pun">:</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//launchpad.net/~ubuntu-desktop/+archive/ubuntu/ubuntu-make</span>
  5. <span class="typ">Press</span><span class="pun">[</span><span class="pln">ENTER</span><span class="pun">]</span><span class="pln"> to </span><span class="kwd">continue</span><span class="kwd">or</span><span class="pln"> ctrl</span><span class="pun">-</span><span class="pln">c to cancel adding it</span>
  6. <span class="pln">gpg</span><span class="pun">:</span><span class="pln"> keyring </span><span class="str">`/tmp/tmpv0vf24us/secring.gpg' created</span>
  7. <span class="str">gpg: keyring `</span><span class="pun">/</span><span class="pln">tmp</span><span class="pun">/</span><span class="pln">tmpv0vf24us</span><span class="pun">/</span><span class="pln">pubring</span><span class="pun">.</span><span class="pln">gpg</span><span class="str">' created</span>
  8. <span class="str">gpg: requesting key A1231595 from hkp server keyserver.ubuntu.com</span>
  9. <span class="str">gpg: /tmp/tmpv0vf24us/trustdb.gpg: trustdb created</span>
  10. <span class="str">gpg: key A1231595: public key "Launchpad PPA for Ubuntu Desktop" imported</span>
  11. <span class="str">gpg: no ultimately trusted keys found</span>
  12. <span class="str">gpg: Total number processed: 1</span>
  13. <span class="str">gpg: imported: 1 (RSA: 1)</span>
  14. <span class="str">OK</span>

然后,更新本地库索引并安装 ubuntu-make。

  1. <span class="com"># apt-get update</span>
  2. <span class="com"># apt-get install ubuntu-make</span>

在我们的 ubuntu 操作系统上安装完 Ubuntu Make 之后,我们可以在一个终端中运行以下命令来安装 Code。

  1. <span class="com"># umake web visual-studio-code</span>

Linux中安装 Visual Studio Code 详解

Umake Web Code

运行完上面的命令之后,会要求我们输入想要的安装路径。然后,会请求我们允许在 ubuntu 系统中安装 Visual Studio Code。我们输入“a”(接受)。输入完后,它会在 ubuntu 机器上下载和安装 Code。最后,我们可以在启动器或者菜单中启动它。

总结

我们已经成功地在 Linux 发行版上安装了 Visual Studio Code。在所有 linux 发行版上安装 Visual Studio Code 都和上面介绍的相似,我们也可以使用 umake 在 Ubuntu 发行版中安装。Umake 是一个安装开发工具,IDEs 和语言的流行工具。我们可以用 Umake 轻松地安装 Android Studios、Eclipse 和很多其它流行 IDE。Visual Studio Code 是基于 Github 上一个叫 Electron 的项目,它是 Atom.io 编辑器的一部分。它有很多 Atom.io 编辑器没有的改进功能。当前 Visual Studio Code 只支持 64 位 linux 操作系统平台。

如果你有任何疑问、建议或者反馈,请在下面的评论框中留言以便我们改进和更新我们的内容。非常感谢!Enjoy :-)

Visual Studio 的详细介绍:请点这里
Visual Studio 的下载地址:请点这里

相关推荐