Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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...
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...
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...
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.
# .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.
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088
Rep:
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.