This page has been machine-translated from the original page.
Introduction
I troubleshot the issue where VSCode can no longer be launched with the code command after running apt update in a Linux environment, so I’m recording the cause and the fix.
I had installed VSCode using a deb file downloaded from the official site and the dpkg -i command.
Table of Contents
Check VSCode information
First, I confirmed that the code package existed.
$sudo dpkg -l | grep code
ii code 1.57.0-1623259737 amd64 Code editing. Redefined.Next, check what the code command is calling.
$which code
/usr/bin/codeApparently, /usr/bin/code is a symbolic link to /usr/share/code/bin/code.
$file /usr/bin/code
/usr/bin/code: symbolic link to /usr/share/code/bin/codeWhen I looked into /usr/share/code/bin/code, it turned out to be an executable shell script, so I checked its contents.
$cat /usr/share/code/bin/code
#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# test that VSCode wasn't installed inside WSL
if grep -qi Microsoft /proc/version && [ -z "$DONT_PROMPT_WSL_INSTALL" ]; then
echo "To use Visual Studio Code with the Windows Subsystem for Linux, please install Visual Studio Code in Windows and uninstall the Linux version in WSL. You can then use the \`code\` command in a WSL terminal just as you would in a normal command prompt." 1>&2
printf "Do you want to continue anyway? [y/N] " 1>&2
read -r YN
YN=$(printf '%s' "$YN" | tr '[:upper:]' '[:lower:]')
case "$YN" in
y | yes )
;;
* )
exit 1
;;
esac
echo "To no longer see this prompt, start Visual Studio Code with the environment variable DONT_PROMPT_WSL_INSTALL defined." 1>&2
fi
# If root, ensure that --user-data-dir or --file-write is specified
if [ "$(id -u)" = "0" ]; then
for i in "$@"
do
case "$i" in
--user-data-dir | --user-data-dir=* | --file-write )
CAN_LAUNCH_AS_ROOT=1
;;
esac
done
if [ -z $CAN_LAUNCH_AS_ROOT ]; then
echo "You are trying to start Visual Studio Code as a super user which isn't recommended. If this was intended, please 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 command -v 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 $?By reading this script, I confirmed that the actual VSCode executable is /usr/share/code/code.
If you run the file command on it, you can confirm that it is an ELF file.
$file /usr/share/code/code
/usr/share/code/code: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=09e8dc044d33f961bfddaa7b20750bdf7d1f3005, not strippedUpgrade VSCode
Now that the preliminary investigation is done, let’s reproduce the issue.
sudo apt update && sudo apt upgrade codeAfter this, VSCode on Linux was upgraded, and I could no longer launch VSCode from the terminal with the code command.
$code
bash: code: command not foundIdentify the problematic part
From the investigation above, we can see that starting VSCode with the code command goes through the following steps.
- The
codecommand calls/usr/bin/code /usr/bin/codeis a symbolic link to/usr/share/code/bin/code/usr/share/code/bin/codeis an executable shell script and calls/usr/share/code/code
Here, I will identify at which step the problem occurs.
Check whether the VSCode binary exists
Let’s work backward from the goal.
Surprisingly, after running apt upgrade code, /usr/share/code/code had disappeared.
$file /usr/share/code/code
/usr/share/code/code: cannot open `/usr/share/code/code' (No such file or directory)I tried apt install, but apparently it had not been uninstalled.
$sudo apt install code
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
code is already the newest version (4.11.5).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.Then, after exploring a few directories, I found an executable called /usr/bin/codium.
Apparently, codium is an application in which VSCode has been made fully open source, and except for appearance-related parts such as Microsoft’s logo, it is almost completely identical to VSCode. (It seems some extensions I always use do not work, though…)
It seems that the VSCode I had originally installed using a deb file downloaded from Microsoft’s page also had the same contents as codium, with only the outer shell being different.
And in the Description of apt show code, I found the following.
Description: Free/Libre Open Source Software Binaries of VSCode (VSCodium)
Transitional package. Moved to codium.Apparently, the code package has moved to codium.
Because of that, when I upgraded code with apt, I could no longer launch the application with the code command.
Solution
I simply created an alias.
alias code=codiumThis lets me launch VSCode (codium) with the same feel as before.
Summary
This time, I troubleshot the issue where the code command stops working after an upgrade in an environment where VSCode had been installed using a deb file downloaded from the official site and the dpkg -i command.