Alexander Suraphel
Alexander Suraphel

Reputation: 10623

.bashrc not sourced on Intellij IDEA's terminal

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?

Upvotes: 39

Views: 36436

Answers (16)

Kai
Kai

Reputation: 849

Open settings, Tools->Terminal->Shell path, just set /bin/bash。Reopen IDE, open terminal to test it. If it doesn't work, run exit and then reopen a new terminal, maybe it will take effects.

Upvotes: 1

Juan Antonio
Juan Antonio

Reputation: 2604

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

Upvotes: 1

Ricardo 2040
Ricardo 2040

Reputation: 191

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.

https://intellij-support.jetbrains.com/hc/en-us/community/posts/205437150-Terminal-not-sourcing-bash-profile?page=1#community_comment_360000167679

Upvotes: 19

Kyle Strand
Kyle Strand

Reputation: 16499

.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!)

enter image description here

Upvotes: 55

Ashok J
Ashok J

Reputation: 3

I just restarted my MAC and it picked up the new stuff.

Upvotes: 0

masoud soroush
masoud soroush

Reputation: 677

On Mac OSX Catalina, "/bin/bash" and ~/.zprofile worked for me:

enter image description here

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.

Upvotes: 9

M C Andrews
M C Andrews

Reputation: 29

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.

Upvotes: 0

Aman Gupta
Aman Gupta

Reputation: 3797

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

Upvotes: 1

Ben
Ben

Reputation: 57287

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).

Upvotes: 0

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 :)

Upvotes: 10

TetraDev
TetraDev

Reputation: 17114

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.

Upvotes: 0

Eidan Spiegel
Eidan Spiegel

Reputation: 307

My settings are in ~/.bash_profile . I solved it using:

echo "source ~/.bash_profile" >> .profile

Upvotes: 3

Zolt&#225;n
Zolt&#225;n

Reputation: 22186

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.

Upvotes: 1

Dimitri Kopriwa
Dimitri Kopriwa

Reputation: 14385

Because > operator doesn't pass the sudo permissions to the write process.

I did this :

echo ". ~/.bashrc" | sudo tee /etc/bash.bashrc

Upvotes: 1

SLePort
SLePort

Reputation: 15461

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   

Upvotes: 13

Ognjen
Ognjen

Reputation: 61

sudo echo ". ~/.bashrc" >> /etc/bash.bashrc

Upvotes: 2

Related Questions