Ubuntu下安装vscode,并解决终端打不开vscode的问题

Visual Studio Code安装

1,使用 apt 安装

Visual Studio Code 在官方的微软 Apt 源仓库中可用。按照下面的步骤进行即可:

以 sudo 用户身份运行下面的命令,更新软件包索引,并且安装依赖软件:

sudo apt update
sudo apt install software-properties-common apt-transport-https wget

使用 wget 命令插入 Microsoft GPG key :

wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -

启用 Visual Studio Code 源仓库,输入:

sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"

一旦 apt 软件源被启用,安装 Visual Studio Code 软件包:

sudo apt install code

当一个新版本被发布时,你可以通过你的桌面标准软件工具,或者在你的终端运行命令,来升级 Visual Studio Code 软件包:

sudo apt update
sudo apt upgrade

2,官网下载

建议在Windows下下载linux版本的vscode,然后再传入ubuntu,地址:Download Visual Studio Code - Mac, Linux, Windows

在ubuntu中下载比较的慢。

3,微软商店下载 

点击进去搜索即可,但我下载时多次被强制中断。

扫描二维码关注公众号,回复: 17167343 查看本文章

终端打不开vscode的问题

在终端窗口中输入如下命令以检验是否已安装gcc:

gcc -v  

若能够正确打印出当前gcc的版本信息,则表示已经预装。若没有预装,则用如下命令安装安装 GNU 编译器工具和 GDB 调试器:

sudo apt update
sudo apt-get install build-essential gdb

没有问题后,安装C/C++扩展

然后进入终端创建一个工程目录,输入:

code .

出现下面的报错:

You are trying to start Visual Studio Code as a super user which isn't recommended. If this was intended, please add the argument `--no-sandbox` and specify an alternate user data directory using the `--user-data-dir` argument.

解决方案1

code --no-sandbox --user-data-dir

解决方案2

source ~/.bashrc 

添加这一行即可: 

alias code='/usr/share/code/code . --no-sandbox --unity-launch'

普通退出可能出现问题:

# 按下Esc ,输入  :wq

E45: 'readonly' option is set (add ! to override)

这里采用强制退出:

:wq!
source ~/.bashrc

猜你喜欢

转载自blog.csdn.net/m0_62919535/article/details/134198172