9

whenever I run eclipse from the shortcut I am unable to correctly build some of my projects because the PATH variable that I configured in .bashrc doesn't get used.

When I run eclipse from my terminal, I can build all my projects perfectly fine because it's running through the correct shell.

The problem is that I want to use the PATH variable from my .bashrc without permanently having a terminal open. I tried this before, but every day I accidentally close the terminal that's running eclipse by accident and lose all my unsaved code.

Can anyone help me?

JREN
  • 3,572
  • 3
  • 27
  • 45

5 Answers5

19

Your tooling probably utilizes the embedded eclipse terminal. This terminal does not start providing your login/user shell. So you need to set the eclipse terminal in your Eclipse preferences to start as --login shell:

Go to:

Preferences -> Terminal -> Local Terminal

and set

"Arguments" to "--login"

restart Eclipse and your users $PATH should be used from now on.

Martin Peter
  • 3,565
  • 2
  • 23
  • 26
12
  1. Edit /usr/share/applications/eclipse.desktop with write privileges, i.e. sudo gedit /usr/share/applications/eclipse.desktop

  2. Change the setting Exec=/usr/bin/eclipse to Exec=bash -ic "/usr/bin/eclipse" and save

The underlying issue is that .bashrc is not loaded in a non-interactive shell. When you start Eclipse normally clicking on its symbol, .bashrc quits early. This solution applies to all programs that are defined by a .desktop file. In contrast, bash -i opens an interactive shell, -c "" runs a command in that shell.

SpamBot
  • 1,438
  • 11
  • 28
  • +1 Yes, this indeed the best and most non-intrusive way to do it. Plus it can be applied to many other applications. I start my Qt Creator in the exact same way. – rbaleksandar Aug 13 '17 at 18:51
4

I can think of two options for this problem:

  • write a small script, export those vars or source your .bashrc before you start your eclipse.
  • define those variables in /etc/environment. then they are not user-scope any more.

I prefer the 1st option.

Kent
  • 189,393
  • 32
  • 233
  • 301
  • 1
    I added the path variable to my .gnomerc file (which is basically the same as the second option) – JREN Aug 08 '13 at 13:02
  • 1
    Also similar to second option, I was able (on my Mint linux) to get this to work by adding my additional PATH manipulation to the ~/.profile file, which is run on login. – jgreen Jan 20 '16 at 21:52
  • Option 3) starting Eclipse from inside bash. At least with Qt Creator it works without any issues. – rbaleksandar Aug 13 '17 at 18:50
3
  1. Create simple script
#!/bin/bash
source /home/user/.environment_variables
/home/user/eclipse_cpp/eclipse -Duser.name="My Name"

2. Next put your all system variables in file /home/user/.environment_variables (any file you want)

My looks like:

export COCOS_ROOT=/home/user/Projects/edukoala
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/

3. Now you can delete your variables in .bashrc and put line

source /home/user/.environment_variables

Everything works fine :)

Gelldur
  • 11,187
  • 7
  • 57
  • 68
1

Well, this is already answered and the answer has been accepted. But this will also work for running your code using Eclipse. You can edit the Run Configurations and set the environment variable there. Then, Eclipse will pick up the variable from this setting while building.

Sumod
  • 3,806
  • 9
  • 50
  • 69