无法打开 Visual Studio Code

Ada*_*her 13 bash visual-studio-code

我已经在装有 Ubuntu 16.04 LTS 的笔记本电脑上安装了 VS Code。我尝试了多种安装方法,结果相同;最近,我在这里遵循了 Cactux 的“新”说明。我试过以两种方式打开应用程序都没有效果。

  • 当我从“应用程序”打开程序时,图标在启动器中显示大约 15 秒然后消失。没有错误弹出。
  • 当我打开一个终端并输入 时code,该命令什么也不做,我会在不到一秒钟的时间内收到一个新提示。

由于我对 Linux 比较陌生,因此我正在努力尝试尝试什么。 which codeyields /usr/bin/code,这是一个 bash 脚本。这是我超越我的深度的地方。

脚本内容

/usr/bin$ cat code
#!/usr/bin/env bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

# If root, ensure that --user-data-dir or --file-write is specified
if [ "$(id -u)" = "0" ]; then
    for i in $@
    do
        if [[ $i == --user-data-dir || $i == --user-data-dir=* || $i == --file-write ]]; then
            CAN_LAUNCH_AS_ROOT=1
        fi
    done
    if [ -z $CAN_LAUNCH_AS_ROOT ]; then
        echo "You are trying to start vscode as a super user which is not recommended. If you really want to, you must specify an alternate user data directory using the --user-data-dir argument." 1>&2
        exit 1
    fi
fi

if [ ! -L $0 ]; then
    # if path is not a symlink, find relatively
    VSCODE_PATH="$(dirname $0)/.."
else
    if which readlink >/dev/null; then
        # if readlink exists, follow the symlink and find relatively
        VSCODE_PATH="$(dirname $(readlink -f $0))/.."
    else
        # else use the standard install location
        VSCODE_PATH="/usr/share/code"
    fi
fi

ELECTRON="$VSCODE_PATH/code"
CLI="$VSCODE_PATH/resources/app/out/cli.js"
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?
Run Code Online (Sandbox Code Playgroud)

调试输出(来自不同目录)

~$ bash -x code
++ id -u
+ '[' 1000 = 0 ']'
+ '[' '!' -L code ']'
++ dirname code
+ VSCODE_PATH=./..
+ ELECTRON=./../code
+ CLI=./../resources/app/out/cli.js
+ ELECTRON_RUN_AS_NODE=1
+ ./../code ./../resources/app/out/cli.js
/usr/bin/code: line 35: ./../code: No such file or directory
+ exit 127

/usr/bin$ bash -x code
++ id -u
+ '[' 1000 = 0 ']'
+ '[' '!' -L code ']'
+ which readlink
+++ readlink -f code
++ dirname /usr/share/code/bin/code
+ VSCODE_PATH=/usr/share/code/bin/..
+ ELECTRON=/usr/share/code/bin/../code
+ CLI=/usr/share/code/bin/../resources/app/out/cli.js
+ ELECTRON_RUN_AS_NODE=1
+ /usr/share/code/bin/../code /usr/share/code/bin/../resources/app/out/cli.js
+ exit 0
Run Code Online (Sandbox Code Playgroud)

路径的内容

~$ $PATH
bash: /home/adam/anaconda3/bin:/home/adam/anaconda3/bin:/home/adam/bin:/home/adam/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin: No such file or directory
Run Code Online (Sandbox Code Playgroud)

任何帮助或建议表示赞赏。

小智 25

我在这里描述了同样的问题,新安装的 Ubuntu 18.04 LTS。我从 conda 安装了 VS Code。

发现如果你运行以下

code --verbose
Run Code Online (Sandbox Code Playgroud)

它会告诉你代码发生了什么。就我而言

code --verbose
[main 20:19:26] Startup error: 
Error: EACCES: permission denied, mkdir '/home/<user>/.config/Code/CachedData'
Run Code Online (Sandbox Code Playgroud)

果然文件夹 ~/.config/Code 由于某种原因具有 root 访问权限。使用 sudo 删除文件夹。

rm -rf /home/<user>/.config/Code 
Run Code Online (Sandbox Code Playgroud)

再次尝试运行代码,它工作正常。


小智 5

我有同样的问题。就像 Robin G 和 Nezir 建议我意识到 /home/user/.config/Code 目录的所有者是“root”。但是,您可以更改该目录的所有权而不是删除它。

sudo chown -R user /home/user/.config/Code

递归更改目标目录下所有文件和目录的所有权需要“-R”选项。

在此之后,ubuntu 18.04 上的 Visual Studio Code v. 1.27 可以在我的机器上正常工作。