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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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 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):
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:
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
$ echo $0
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.
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.
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.
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?