Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating environmental variables in Visual Studio Code on Linux

I changed the environmental variable LD_LIBRARY_PATH from the Ubuntu terminal (because I was receiving an error) and the changes were applied when I ran code (a Python code) from the terminal. But when I ran the same script from the Visual Studio Code, the error remains. How to update the environmental variable so that Visual Studio Code sees it, as well?

like image 253
cerebrou Avatar asked Nov 08 '22 09:11

cerebrou


1 Answers

Environment variables are passed from parent process to child process; they are not (say) global to the system or the user. If you change a variable in one shell, the change is only seen in that shell and any processes started from that shell. So the simplest solution is to change the variable and then start VSCode from that same shell:

  $ export LD_LIBRARY_PATH=/some/useful/path
  $ code

If you want to keep using that shell for other things, run it in the background:

  $ code >/dev/null 2>&1 &

The redirection to /dev/null is needed because otherwise VSCode prints logging information periodically, and that output will be mixed with whatever else you're doing.

If you want to set the variable permanently, see the question How do I set a user environment variable? (permanently, not session). After following those instructions, you'll need to start a new shell (and possibly even logout and login) first so the settings take effect. Then launch VSCode from the new shell.

like image 133
Scott McPeak Avatar answered Jan 04 '23 01:01

Scott McPeak