Unable to open visual studio code in Ubuntu 20.04

I tried installing visual studio code by snap as well as apt in both cases it doesn’t work. refer to trace below after hitting code --verbose.

Other observations –

  1. It works with sudo code --user-data-dir its just not normal.
  2. When tried from apps->launcher icon blank window shows up.
  3. Does not seem to be issue with --disable-gpu faced by many people
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Failed to get 'appData' path
    at App.l._setDefaultAppPaths (electron/js2c/browser_init.js:17:1420)
    at Object.<anonymous> (electron/js2c/browser_init.js:217:2440)
    at Object../lib/browser/init.ts (electron/js2c/browser_init.js:217:3716)
    at __webpack_require__ (electron/js2c/browser_init.js:1:128)
    at electron/js2c/browser_init.js:1:1200
    at electron/js2c/browser_init.js:1:1267
    at NativeModule.compile (internal/bootstrap/loaders.js:287:5)
    at NativeModule.compileForPublicLoader (internal/bootstrap/loaders.js:222:8)
    at loadNativeModule (internal/modules/cjs/helpers.js:23:9)
    at Module._load (internal/modules/cjs/loader.js:745:15)
/usr/lib/x86_64-linux-gnu/gio/modules/libgvfsdbus.so: undefined symbol: g_date_time_format_iso8601
Failed to load module: /usr/lib/x86_64-linux-gnu/gio/modules/libgvfsdbus.so
[15861:1112/150521.850343:ERROR:gl_surface_glx.cc(90)] glXGetFBConfigs failed.
[15861:1112/150521.850568:ERROR:gl_surface_glx.cc(130)] Failed to get GLXConfig
[15861:1112/150521.850684:ERROR:gl_surface_glx.cc(479)] CreateDummyWindow(gfx::GetXDisplay()) failed
[15861:1112/150521.850761:ERROR:gl_initializer_x11.cc(148)] GLSurfaceGLX::InitializeOneOff failed.
[15861:1112/150521.854457:WARNING:x11_util.cc(1520)] X error received: serial 218, error_code 8 (BadMatch (invalid parameter attributes)), request_code 78, minor_code 0 (X_CreateColormap)
[15861:1112/150521.854938:ERROR:viz_main_impl.cc(152)] Exiting GPU process due to errors during initialization

I tried many things but no success.
HELP!

Output of apt-cache policy gvfs:*; readelf -s /usr/lib/x86_64-linux-gnu/gio/modules/libgvfsdbus.so | grep g_date_time ; snap info --verbose code

gvfs:
  Installed: 1.44.1-1ubuntu1
  Candidate: 1.44.1-1ubuntu1
  Version table:
 *** 1.44.1-1ubuntu1 500
        500 http://in.archive.ubuntu.com/ubuntu focal/main amd64 Packages
        100 /var/lib/dpkg/status
gvfs:i386:
  Installed: (none)
  Candidate: 1.44.1-1ubuntu1
  Version table:
     1.44.1-1ubuntu1 500
        500 http://in.archive.ubuntu.com/ubuntu focal/main i386 Packages
     6: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND g_date_time_unref
   265: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND g_date_time_new_now_local
   463: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND g_date_time_format_iso860
name:    code
summary: Code editing. Redefined.
health:
  status:  unknown
  message: health has not been set
publisher: Visual Studio Code (vscode✓)
store-url: https://snapcraft.io/code
contact:   https://twitter.com/code
license:   unset
description: |
  Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and
  is available for Linux, macOS and Windows. It comes with built-in support for JavaScript,
  TypeScript and Node.js and has a rich ecosystem of extensions for other languages (such as C++,
  C#, Java, Python, PHP, Go) and runtimes (such as .NET and Unity).
  
  By downloading and using Visual Studio Code, you agree to the license terms
  (https://code.visualstudio.com/License/) and privacy statement
  (https://privacy.microsoft.com/en-us/privacystatement). Visual Studio Code automatically sends
  telemetry data and crash dumps to help us improve the product. If you would prefer not to have
  this data sent please go see
  https://code.visualstudio.com/docs/supporting/FAQ#_how-to-disable-crash-reporting to learn how to
  disable it.
  
  VSCode
  https://github.com/Microsoft/vscode
commands:
  - code
  - code.url-handler
notes:               
  private:           false
  confinement:       classic
  devmode:           false
  jailmode:          false
  trymode:           false
  enabled:           true
  broken:            false
  ignore-validation: false
snap-id:      Ht0aUHi7ofh9Fbwh6m7jUN2pAy6kzBiu
tracking:     latest/stable
refresh-date: today at 15:04 IST
channels:
  latest/stable:    e5a624b7 2020-11-11 (50) 153MB classic
  latest/candidate: ↑                              
  latest/beta:      ↑                              
  latest/edge:      ↑                              
installed:          e5a624b7            (50) 153MB classic

Asked By: NotABot

||

After digging internet for 4 to 6 hours found that issue was related to HOME environment variable which was wrongly set to /root changed it to /home/your_username and it worked.

Instructions-

  1. Open .bashrc file from /home/your_username (not /root)
  2. Add this to the last new line – export HOME=/home/your_username
  3. Restart computer or execute source .bashrc

Answered By: NotABot

this worked :

try first

$ code --disable-gpu

otherwise

$ code --disable-gpu --disable-software-rasterizer
Answered By: do7
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.