I have some aliased defined on my .bashrc
that I'd like to use on my Intellij IDEA's terminal. Why is .bashrc
not sourced?

- 10,103
- 10
- 55
- 90
-
Useful to understand why: [Why doesn't .bashrc run automatically?](https://apple.stackexchange.com/a/13019/116146) and [What is the difference between .bash_profile and .bashrc?](https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc) – Ricardo Mar 19 '21 at 00:49
-
My issue was with launching from the doc as a GUI for Android Studio. I updated my system-wide path from this answer: https://stackoverflow.com/a/3756686/1451443 – notbad.jpeg May 01 '22 at 20:18
15 Answers
.bashrc
is only loaded when Bash is running in "interactive" mode. For some reason, IntelliJ defaults to running Bash in non-interactive mode, but this is easy to change. Open the IntelliJ Settings window, then open "Tools -> Terminal", and add -i
to the Shell path.
(Note that in this screenshot, I have also changed the default shell, because I'm on a Mac, which makes it difficult to update /bin/bash
. Unless you have installed a different version of Bash, do not blindly copy this change!)

- 3,696
- 5
- 36
- 50

- 15,941
- 8
- 72
- 167
-
-
3So if your `Terminal > Shell path` setting calls `bash -i` (interactive), it will run `~/.bashrc` on opening a new tab; if it calls `bash` (non-interactive), it will run `~/.bash_profile`. *Checked against WebStorm 2020.3.3 on macOS Catalina.* – Ricardo Mar 19 '21 at 00:42
-
This solution does not work on my windows git bash environment. Instead what did work was this solution provided: https://intellij-support.jetbrains.com/hc/en-us/community/posts/205437150/comments/204862230 – Barney Feb 07 '22 at 20:54
-
1@Barney Interesting... `--login -i` should also work, but `login` may not be what you want. I don't know why `-i` on its own wouldn't fix the issue for you, though. – Kyle Strand Feb 09 '22 at 19:18
-
1@KyleStrand oh `--login` or `-l` alone (without `-i`) does what I need which is to source `.bash_profile`. This SO question is about `.bashrc` so I now realize this is not apples to oranges. Thank you anyway and feel free to disregard! – Barney Feb 10 '22 at 06:24
Had the same issue with IntelliJ.
Solved this by setting the value /bin/bash --login
in setting->Tools->Terminal->Shell path
.
/bin/bash --login
forces the bash to read the ~/.bash_profile
.

- 25,272
- 21
- 67
- 103

- 151
- 1
- 3
-
This is the only solution that worked for me. However I do not have a ~/.bash_profile – Brice Jul 25 '21 at 10:03
In your home directory, add theses lines to .profile
(create the file if it does not exist), in order to source .bashrc
:
if [ "$SHELL" = "/bin/bash" ]; then
. ~/.bashrc
fi

- 10,103
- 10
- 55
- 90

- 15,211
- 3
- 34
- 44
-
Kenavoz, I had found this solution.. I asked this question to find out why it's not source by default and why your solution works. thanks – Alexander Suraphel Apr 13 '16 at 08:34
-
Did you define you bash path in the Intellij IDEA's terminal settings ? – SLePort Apr 13 '16 at 09:04
-
-
I don't know the default. Bash is not universal and it could haved explained why `.bashrc` is not sourced. – SLePort Apr 14 '16 at 05:36
-
-
Kenavoz, I just checked and my `~/.profile` has something like: # if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi I thought it should be enough. right? – Alexander Suraphel Apr 27 '16 at 08:23
-
I would change the file test to `if [ -r "$HOME/.bashrc" ]` to check if it exists and has read permissions. You may also test the `$BASH` variable instead of `$BASH_VERSION`. – SLePort Apr 27 '16 at 09:42
For me, changing the line
Exec="/opt/idea-IU-183.4284.148/bin/idea.sh" %f
to
Exec=bash -ic "/opt/idea-IU-183.4284.148/bin/idea.sh" %f
worked. We exploit the hack that the interactive shell loads .bashrc
:)

- 8,551
- 11
- 53
- 102
-
While the solution is highly installation-specific, I've found it useful in another case. I use node.js with `nvm` and for node to be available in `PATH`, `.bashrc` should be executed before IDE. I've improved the solution like this: `bash -ic "exec /path/to/webstorm.sh %f"` That is, handle `%f` and use `exec` to replace bash. – Konstantin Pelepelin Jul 06 '20 at 15:27
-
-
Also works for me on Kubuntu 20.04. NPM installed via NPM was not available during maven builds delegating to shell exec. – Marius Schmidt Jan 24 '21 at 21:50
-
This worked atleast on ubuntu 20.04.5 LTS. If some one failing to find path where to replace. Here it is ~/.local/share/applications/jetbrains-rider.desktop or intellj or webstorm – Azerue Nov 16 '22 at 09:06
On Mac OSX Catalina, "/bin/bash"
and ~/.zprofile
worked for me:
Update:
Apple has changed the default shell to zsh.
Therefore you have to rename your configuration files. .bashrc
is now .zshrc
and .bash_profile
is now .zprofile
.

- 677
- 11
- 21
-
1The important information for me was, that ZSH is now the new standard in Mac OS Catalina. – Chris P. Bacon May 22 '20 at 13:37
My settings are in ~/.bash_profile . I solved it using:
echo "source ~/.bash_profile" >> .profile

- 307
- 1
- 2
- 10
sudo echo ". ~/.bashrc" >> /etc/bash.bashrc

- 10,103
- 10
- 55
- 90

- 61
- 3
-
1@AlexanderSuraphel As I understood, idea loads only default bash profile. With adding source of your home .bashrc at the end of it, it will be loaded by default. btw, first answer doesn't work for me. – Ognjen Sep 19 '16 at 13:19
-
7Even though this might work, I wouldn't do this. I quite often make changes to my .bashrc -file. The .bashrc -file contains configuration for an individual user whereas /etc/bash.bashrc is used for every user using the system. The command suggested simply adds my entire configuration to the system configuration which will then apply it to every user using the system. Apparently Intellij IDEA picks up the system-file, but not the file intended for the individual user. – Matti Nov 30 '17 at 06:40
Because >
operator doesn't pass the sudo permissions to the write process.
I did this :
echo ". ~/.bashrc" | sudo tee /etc/bash.bashrc

- 13,139
- 27
- 98
- 204
I noticed that .bashrc
isn't sourced only when I first install IntelliJ and run it directly via the idea.sh
script in bin/
.
Once I create the desktop entry via Tools -> Create Desktop Entry...
and start it from the Ubuntu dash, .bashrc
is sourced properly.

- 21,321
- 14
- 93
- 134
If you have recently moved to zsh from bash then go to ~/.zshrc
file and update $PATH variable there:
Default value in .zshrc
:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
Change to same PATH variable set in .bashrc
and uncomment it
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:<my-bash-paths>:$PATH

- 3,627
- 4
- 40
- 64
None of these answers worked for me. What did work is
sudo nano /etc/environment
...then manually adding my export
and alias
commands here to make them system wide.
But be careful, do NOT mess up the PATH or you'll have trouble logging back in to your desktop environment, or many other issues.

- 16,074
- 6
- 60
- 61
I had this problem because the default shell had been changed to zsh
.
I echoed the shell name with echo $SHELL
to see this (thanks How to get default shell).
Then I changed it back to /bin/bash
with this command: chsh -s /bin/bash
(thanks https://apple.stackexchange.com/a/100476/176809).

- 54,723
- 49
- 178
- 224
Create a bash script with the content;
echo "source ~/.bash_profile" >> .profile
Then in Intellij go to preferences/tools/Startup Tasks;
create a run configuration that runs your bash script and you're good to go.

- 29
- 1
For me at least, the only thing that works was to put this in the Shell path
variable inside of Tools > Terminal :
/bin/bash --rcfile ~/.bashrc

- 2,451
- 3
- 24
- 34
-
Sorry for the abuse of system here. Congrats on being my "Strunk and White" twin -- we both received this badge around the same time and have similar overall points. And this despite your English! I also like the "unsung hero" badge - don't have one myself, but a nice concept. – Josiah Yoder Dec 02 '22 at 19:25