LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can't permanently change path (https://www.linuxquestions.org/questions/linux-newbie-8/cant-permanently-change-path-285415/)

SuperRunt 02-02-2005 01:17 PM

Can't permanently change path
 
I have tried a few things I found searching the net, but it's not working...
I would like to add a directory (from my home directory) to PATH, so the compiler can find my personal libraries.
This is what I've done so far:
$ PATH = $PATH:/home/programs/[name of library]
$ export PATH

$ echo $PATH returns :/home/programs/[name of library]

But it doesn't stay this way!
When I exit and then open a new shell terminal, echo $PATH returns my "old" PATH without the addition.

I read something about changing the bashrc file, but I opened it, and I don't understand what kind of changes I could do...

Thanx!

secesh 02-02-2005 01:18 PM

put it in your rc file -- with bash, use ~/.bashrc

SuperRunt 02-02-2005 01:24 PM

Thanx! That was fast!
Still confused...

This is what my ~/.bashrc file looks like:

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# enable programmable completion features
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi



Where do I put the /home/programs/{name} part?

abisko00 02-02-2005 01:35 PM

Add a line like you did on console:

Code:

export PATH=$PATH:/home/programs/lib
You may also put this in /etc/bashrc or /etc/profile for global definition.

But now a noob question back: aren't libraries better added to the system by a tool like ldconfig? I thought this method is usually used for calling commands...

SuperRunt 02-02-2005 01:55 PM

I did that, but it doesn't "stick".
As soon as I close the shell terminal, I'm back to the old PATH.

I don't know anything about Idconfig. Can you use that for "home made" libraries?


By the way:
We should be telling "Norwegian and Swede" - jokes, since I'm Norwegian (even though I'm located in the US)... Juust kidding.

__J 02-02-2005 02:03 PM

what exactly is the directory structure? (like /home/programs/????? ( are there only libs in here or executables to?)).

as far as ldconfig, define "home made" libs (are they shared libraries, static, objects, etc..).

SuperRunt 02-02-2005 02:12 PM

I'll give an example, so I'm sure I give enough info:

One Directory is Printer. It is in ~/programs which I created for this purpose.
Printer has two directories: /include and /lib.
/include has one file named Printer.h, and /lib has one file named Printer.cpp.
These are from my C++ instructor, and are supposed to be used in a program to print to file.

Sorry I'm so vague, I've just been doing this for a couple of weeks...

Thank you

__J 02-02-2005 02:17 PM

well, if you add at the bottom of ~/.bashrc the export line above that should work. after you compile Printer.cpp try typing the name of the executable(Printer) and see if it works.

SuperRunt 02-02-2005 02:44 PM

OK Just making sure
My .bashrc should look like this after I'm done?

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# enable programmable completion features
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

export PATH = $PATH:/home/programs/Printer

If I need to add on more, can I just add another line?
I REALLY appreciate your help!

Electro 02-02-2005 07:09 PM

Code:

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# enable programmable completion features
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

export PATH = $PATH:/home/programs/Printer

The code above is ok, but for efficency use:

Code:

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# enable programmable completion features
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
PATH=$PATH:/home/programs/Printer

export PATH

If you want to add more variables just add them. You can add multiple variables to the same export line. For example if you want a variable BOB be globalized.

Code:

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# enable programmable completion features
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
PATH=$PATH:/home/programs/Printer
BOB="his name here"

export PATH BOB

The variables PATH and BOB will be exported at the same time.

.bashrc is a BASH script that gets run when you login. There is also .logout (I think) or was it .bash_logout if you want Linux do something like clean up before logging out.

SuperRunt 02-02-2005 11:27 PM

Thank you!
This is exactly what I've been trying to find.

IBall 02-02-2005 11:59 PM

You can also put the export PATH = ..... line in the file ~/.bash_profile

.bash_profile is read when you invoke a login shell, .bashrc is read when you invoke a non login shell. I am not 100% sure what an xterm is invoked as.
--Ian


All times are GMT -5. The time now is 07:46 AM.