14

I've installed VS Code on my laptop with Ubuntu 16.04 LTS. I've tried multiple installation methods with identical results; most recently, I followed the "new" instructions from Cactux here. I've tried opening the application two ways to no effect.

  • When I open the program from 'Applications', the icon shows in the launcher for approximately 15 seconds and then disappears. No error pops up.
  • When I open a terminal and type code, the command does nothing and I get a new prompt in less than a second.

I'm struggling with what to try since I'm relatively new to Linux. which code yields /usr/bin/code, which is a bash script. This is where I get outside my depth.

Contents of script

/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 $?

Debug output (from different directories)

~$ 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

Contents of PATH

~$ $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

Any help or suggestions are appreciated.

2
  • 1
    Make sure you have your packages updated. You can verify this with these commands: 1) sudo apt update 2) sudo apt upgrade. If you get any errors, address the errors. Then try to run the apt from the terminal and check for errors. Apr 7 '18 at 20:36
  • Only this worked for me ``` snap run code ```
    – Thomas G.
    Jul 15 '19 at 7:01
29

I had the same problem described here, new install of Ubuntu 18.04 LTS. I installed VS Code from conda.

Discovered that if you run the following

code --verbose

It will tell you what is going on with Code. In my case

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

sure enough the folder ~/.config/Code had root access permissions for some reason. Deleted the folder using sudo.

rm -rf /home/<user>/.config/Code 

Tried again to run code and it working fine.

3
  • 1
    If they do they lost all personal configuration files inside her VSCode Studio. Like Snippets and other's configuration extension stuff. I don't suggest you do this before making a backup to restore manually your custom files. Jun 4 at 18:43
  • This worked for me. The verbose error message was: [2784052:0628/225625.439220:FATAL:platform_shared_memory_region_posix.cc(255)] This is frequently caused by incorrect permissions on /dev/shm. Try 'sudo chmod 1777 /dev/shm' to fix.
    – skrtbhtngr
    Jun 28 at 13:56
  • "Losing all personal configuration files" is not a concern here for any user who had the problem I did. I was completely unable to get VSC to load from a new install; there were no config files to lose. Oct 1 at 7:57
5

I had the same problem. Like Robin G and Nezir suggested I realized that the owner of the /home/user/.config/Code driectory is the "root". However, You could just change the ownership of that directory instead of removing it.

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

"-R" option is needed to recursively change the ownership of all the files and directories under the target directory.

After this the Visual Studio Code v. 1.27 on ubuntu 18.04 works as it is supposed to on my machine.

1
  • At least I learnt something new: chown command Oct 26 '18 at 18:59
2

Debug the bash with the correct command

To debug you should use following command:

bash --debugger `which code`

This will run the bash script line per line. To go to the next line simply type n and return. Post the output than we will see more.

Installing via snap (for Ubuntu versions > 18.04)

BTW Ubuntu 18.04 LTS (Long term release) now supports code directly and you can install it via snap package:

Show version and info of ubuntu supported snap:

snap info code

and to install it

sudo snap install code 

I personal prefer to install it via apt. Therefore follow this instruction from microsoft:

Installing VS Code

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'

This will download the gpg key and copy and make the apt files. Then you can simply update and install vs code:

sudo apt-get update
sudo apt-get install code
  • The advantage of this installation method is that you can simple update vscode using the apt-get update command. Works fine and I use vs code with the vim plugin for over 2 years (c, c++, python, md, latex, html, javascript ...).
1
  • No dice. At this point though, I actually can just wait for 18.04. Thanks for the tip. Apr 8 '18 at 1:44
1

I had the similar problem here:

https://github.com/Microsoft/vscode/issues/55774#issuecomment-412774473

and fixed it with "delete the /home/user/.config/Code folder"

Thank you!

1

Try in terminal

code --user-data-dir

Worked for me.

1

Open your terminal and run the following commands:

  1. sudo rm -rf /home/your_username/.config/Code

    (Replace your_username with your actual username.)

    Then provide your password and press Enter.

  2. code --verbose

0

VS code may silently fail to open if you don't have required dependencies.

From this page:

sudo apt-get install -f # Install dependencies
1
  • I hope one sentence is enough to explain what it means ` install dependencies ` Jun 16 '18 at 19:39
0
code --verbose

alone did the trick for me when Code failed to start (got jammed) after X system crash. However, the files opened were not the most recent, but some ancient ones.

0

In my case when I ran code --verbose the error was:

Error: ENOSPC: System limit for number of file watchers reached, watch '/snap/code'

So I increased number of file watchers to its maximum by modifying /etc/sysctl.conf and adding this to at the end of the file:

fs.inotify.max_user_watches=524288

Then I had to run this command to load the value in system:

sudo sysctl -p

Now I can run VScode with no issues

Not the answer you're looking for? Browse other questions tagged or ask your own question.