Ubuntu 运行 VSCode前言问题概述解决方案前言Ubuntu 版本如下roottest-virtual-machine:~# cat /etc/os-releasePRETTY_NAMEUbuntu 24.04.4 LTSNAMEUbuntuVERSION_ID24.04VERSION24.04.4 LTS (Noble Numbat)VERSION_CODENAMEnobleIDubuntuID_LIKEdebianHOME_URLhttps://www.ubuntu.com/SUPPORT_URLhttps://help.ubuntu.com/BUG_REPORT_URLhttps://bugs.launchpad.net/ubuntu/PRIVACY_POLICY_URLhttps://www.ubuntu.com/legal/terms-and-policies/privacy-policyUBUNTU_CODENAMEnobleLOGOubuntu-logo roottest-virtual-machine:~#VSCode 安装参考《Ubuntu 22.04 版本常用设置》问题概述图形化使用root用户登录后执行code 不能启动 VSCode报错信息如下roottest-virtual-machine:~/Desktop# code [1]3485roottest-virtual-machine:~/Desktop# You are trying to start Visual Studio Code as a super user which isnt 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] Exit1code roottest-virtual-machine:~/Desktop#roottest-virtual-machine:~/Desktop#roottest-virtual-machine:~/Desktop# codeYou are trying to start Visual Studio Code as a super userwhichisnt recommended. If this was intended, pleaseaddthe argument--no-sandboxand specify an alternate user data directory using the--user-data-dirargument. roottest-virtual-machine:~/Desktop#解决方案VS Code 禁止 root 直接启动出于安全保护所以报错退出。执行以下命令后在执行code echoalias codecode --no-sandbox --user-data-dir/root/vscode/root/.bashrcsource/root/.bashrc说明--no-sandbox关闭安全沙箱root 必须加--user-data-dir指定 root 专用配置目录若有转载请标明出处https://blog.csdn.net/CharlesYuangc/article/details/160472449