'VSCode Integrated Terminal Doesn't Load .bashrc or .bash_profile

I have the following files to handle shell configuration:

#~/.bash_profile
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

and

#~/.bashrc
... configure shell

If I open VSCode from the command line using code, my .bashrc is loaded whenever I add a new instance of the integrated shell.

However if I open VSCode via its icon, only my .profile is loaded.

How can I ensure my .bashrc is loaded instead?

I've tried various settings for the terminal.integrated.shellArgs.osx setting without any luck.



Solution 1:[1]

Another possible solution that just worked for me. The settings.json file (whcih you can access in File > Preferences > Settings > Features > terminal > Integrated > Automation Shell: Linux) had a parameter

    "terminal.integrated.inheritEnv": false

set to false by default. Changing it to true fixed the problem in my case.

Solution 2:[2]

VSCode has deprecated "terminal.integrated.shellArgs.osx" in favor of using profiles. This does the trick for bash in osx. Omit the first line if you don't want bash to be your default profile:

  "terminal.integrated.defaultProfile.osx": "bash",
  "terminal.integrated.profiles.osx": {
    "bash": {
      "path": "bash",
      "args": ["-l"]
    }
  }

Solution 3:[3]

I had the same problem with the Intellij Idea terminal on a Mac, the solution is the same for both. In settings change the path to the integrated terminal to "/bin/bash". Hope that helps.

enter image description here

Solution 4:[4]

You could also try the following:

1 Create a file named /usr/local/bin/bash-login and add :

#!/bin/bash
bash -l

2 Run:

chmod +x /usr/local/bin/bash-login 

to make it executable.

3 On your VSC user settings add

   { "terminal.integrated.shell.osx": "/usr/local/bin/bash-login" }

The solution was described at https://github.com/Microsoft/vscode/issues/7263.

Hope it helps

Solution 5:[5]

"terminal.integrated.shellArgs.osx": ["-l"] is deprecated.

I personally wanted to use .bash_profile, so I made a .bashrc with this:

if [ -f ~/.bashrc ]; then
   source ~/.bash_profile
fi

And then I had to do a full computer restart (just restarting VS code didn't work).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3091644
Solution 2 ahaurat
Solution 3 Tony Ly
Solution 4
Solution 5