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 am trying to compile something and need to add a path variable to my .profile file I think. Underneath PATH="$HOME/bin:$PATH" I added
PATH="$home/rich/X/Development/Android/android-ndk-r8/ndk-build" which is where ndk-build is located. I want to be able to run this from any location by simply typing ndk-build. I have saved this but when I type ndk-build it tells me that the command is not found. Does anyone know where I am going wrong here?
I added PATH="$home/rich/X/Development/Android/android-ndk-r8/ndk-build" which is where ndk-build is located.
This is not the right way to go: the HOME variable is uppercase and maybe it includes also the rich directory, then you forgot to add the current PATH. It should be:
Regarding the proper location fro the statement, it depends from the type of invocation of the shell session. Please, take a look at section Bash Startup Files in the reference guide for details.
I changed the path to that posted above but it still isn't working. From what I read on the site I think it should be ok to add it into the .profile file. Any ideas why it still isnt working?
I think it should be ok to add it into the .profile file. Any ideas why it still isnt working?
Yes. I think .profile is not the right place. If you open a terminal in your graphical desktop environment you're running an interactive non-login shell and in that case (quoting from man bash):
Quote:
When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc then ~/.bashrc when those files exist and are readable.
In case you're running a login shell .profile could still not be the correct place:
Quote:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
This means that if there is a .bash_profile or a .bash_login file in your home directory, .profile will be ignored, since only the first encountered of these three is sourced.
Moreover, on many linux distributions the $HOME/.bash_profile contains some lines of code that check for the existence of $HOME/.bashrc and if it exists it's sourced, making a login shell read .bashrc as well.
In conclusion, the right place could be $HOME/.bashrc and/or $HOME/.bash_profile, but I would prefer the former for the reason explained above. On the other hand if you want to apply these changes/additions on a system basis (that is available to all users) you can put them in /etc/bash.bashrc or /etc/profile.
For the sake of completeness, what is a login shell? It is that one you start by entering your credentials, that is
the shell that runs beneath a graphical desktop environment,
the shell invoked from a virtual console (e.g. ALT-CTRL-F1, ALT-CTRL-F2 and so on),
the shell invoked remotely through ssh.
How do you recognize it is a login shell? By means of
Code:
$ echo $0
-bash
where the hyphen before bash denotes it is a login shell.
Thanks for the amazing and very thorough response! I always find it incredible that people on here are so helpful and I can't thank you enough. Once I understand enough I'm looking forward to being able to share my knowledge too.
Ok.
The trouble I am having now is that I cant change the bash.bashrc file as it is read only and the user is ROOT. When I try to log in using sudo it asks for a password and ........well .....I can't log in. Is there anyway that I can change the read/write privileges otherwise?
Thanks for the amazing and very thorough response! I always find it incredible that people on here are so helpful and I can't thank you enough.
You're welcome!
Quote:
The trouble I am having now is that I cant change the bash.bashrc file as it is read only and the user is ROOT. When I try to log in using sudo it asks for a password and ........well .....I can't log in. Is there anyway that I can change the read/write privileges otherwise
Well... if you don't have root privileges, maybe you don't really need to make the software available to all users. On the other hand if you are a sudoer (that is a user able to gain administrative privileges for some tasks through sudo) you have to insert your password when prompted.
BTW, just to clarify, is this a multi-user system or is it your personal machine? It makes the difference: if it is a multi-user system and the software installed in a non-conventional location must be shared among the users, then /etc/bash.bashrc can be the choice, or even better a newly created file in /etc/profile.d (this is another story, still not mentioned above). If it is your system or the software has to be used by... you, then your personal $HOME/.bashrc is the file to edit.
It is my personal machine. I'm not sure why I can't log into sudo as the password could only be a certain number of things and none of them work. Would it definitley be a password that I have chosen at somepoint?
I only really need to be able to edit the bash.bashrc file by any means really, or more accurately add a path variable by some means to something so that I can compile something from anywhere (That sounds very ambigous I know) :-)
If you're running Ubuntu, there is no root's password so you should be able to use your user's password, unless your system does an automatic login and you forgot it completely! This problem can be addressed in one way or another and there are plenty of tutorials on how to reset a lost password (you can try the LQ search engine as well).
Regarding the original topic, since it is your personal machine I'd suggest to edit $HOME/.bashrc and leave /etc/bash.bashrc alone, unless you need to change it for other reasons not covered here.
to my $HOME/.bashrc file but it still won't compile. Is there somewhere specific I should add it into the file as I have simply just added it on at the end?
I am still stuck on this. Does anyone know if there is somewhere specific in the /.bashrc file that I need to add my PATH variable to? Also, does it need to point to the thing that to point to the directory that contains the file I want to link to or to the actual file itself.
Your help on this would be most appreciated as I can't move forwards at the moment.
can you tell me what is that file? you can simply execute: file $home/rich/X/Development/Android/android-ndk-r8/ndk-build
If it was a text file (probably a shell script) what is in the first line?
Have you checked the permissions on that file? What about the execute flag?
The PATH needs to point to the directory, not the file itself
If ndk-build is the only thing in that directory that you need, you could also just create an alias for it without changing your PATH at all, by adding the following into your $HOME/.bashrc
Code:
alias ndk-build="$HOME/rich/X/Development/Android/android-ndk-r8/ndk-build"
Also, are you sure $HOME/rich is where you mean to look? Assuming rich is the user, the location would be either:
/home/rich/
OR
$HOME
Since $HOME is an environment variable that points to the user's home directory.
Unless of course "rich" is a directory inside your user's home directory, in which case you have it right.
Last edited by suicidaleggroll; 05-30-2012 at 12:18 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.