LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 05-27-2012, 10:20 AM   #1
Taylrl
Member
 
Registered: Jul 2010
Distribution: Ubuntu
Posts: 34

Rep: Reputation: 0
Adding a path variable


Hi,

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?

Richard
 
Old 05-27-2012, 10:26 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Taylrl View Post
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:
Code:
PATH=$HOME/X/Development/Android/android-ndk-r8/ndk-buil:${PATH}
export PATH
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.
 
Old 05-27-2012, 02:02 PM   #3
Taylrl
Member
 
Registered: Jul 2010
Distribution: Ubuntu
Posts: 34

Original Poster
Rep: Reputation: 0
Thanks for your respone :-)

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?

Cheers!
 
Old 05-27-2012, 02:08 PM   #4
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,378

Rep: Reputation: 135Reputation: 135
Add this in your .profile:

Quote:
PATH="$HOME/rich/X/Development/Android/android-ndk-r8/ndk-build:$HOME/bin:$PATH"
export PATH
Then just logout and login again and try.

Last edited by divyashree; 05-27-2012 at 02:11 PM.
 
Old 05-27-2012, 02:35 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Taylrl View Post
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.

Last edited by colucix; 05-27-2012 at 02:37 PM.
 
1 members found this post helpful.
Old 05-28-2012, 02:45 PM   #6
Taylrl
Member
 
Registered: Jul 2010
Distribution: Ubuntu
Posts: 34

Original Poster
Rep: Reputation: 0
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?
 
Old 05-28-2012, 03:21 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Taylrl View Post
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.
 
Old 05-28-2012, 03:27 PM   #8
Taylrl
Member
 
Registered: Jul 2010
Distribution: Ubuntu
Posts: 34

Original Poster
Rep: Reputation: 0
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) :-)

Last edited by Taylrl; 05-28-2012 at 03:31 PM.
 
Old 05-28-2012, 03:38 PM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
Old 05-29-2012, 02:29 PM   #10
Taylrl
Member
 
Registered: Jul 2010
Distribution: Ubuntu
Posts: 34

Original Poster
Rep: Reputation: 0
Thanks again! Ok, I am around the password problem.

I have added
Code:
PATH="$HOME/rich/X/Development/Android/android-ndk-r8/ndk-build:$HOME/bin:$PATH"
export PATH
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?

Cheers!
 
Old 05-30-2012, 07:46 AM   #11
Taylrl
Member
 
Registered: Jul 2010
Distribution: Ubuntu
Posts: 34

Original Poster
Rep: Reputation: 0
Heyyy,

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.

Thanks!
 
Old 05-30-2012, 08:07 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,257

Rep: Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838
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?
 
Old 05-30-2012, 11:56 AM   #13
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
First open a new terminal and check if the environment variable PATH has been correctly setup:
Code:
echo $PATH
and post the output here. Then please, post the output of
Code:
ls -l $HOME/rich/X/Development/Android/android-ndk-r8/ndk-build
and the exact command and the error message you get.
 
Old 05-30-2012, 12:15 PM   #14
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141
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.
 
Old 05-30-2012, 03:11 PM   #15
Taylrl
Member
 
Registered: Jul 2010
Distribution: Ubuntu
Posts: 34

Original Poster
Rep: Reputation: 0
Thanks people! :-)

Quote:
Originally Posted by colucix View Post
First open a new terminal and check if the environment variable PATH has been correctly setup:
Code:
echo $PATH
and post the output here.
What I got was

Code:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Then when I typed

Quote:
Originally Posted by colucix View Post
Code:
ls -l $HOME/rich/X/Development/Android/android-ndk-r8/ndk-build
This made me realise that my PATH wasn't pointing in the right place and I have now corrected it.

Thanks suicidaleggroll, you made me realise this too. I consequently changed the PATH to

Code:
PATH="$HOME/X/Development/Android/android-ndk-r8:$HOME/bin:$PATH"
export PATH
Which is now pointing to the directory that contains the file I want to execute, it didn't execute. I then tried adding

Code:
alias ndk-build="$HOME/rich/X/Development/Android/android-ndk-r8"
into $HOME/.bashrc instead (that is pointing at the directory and not the file) but that didn't seem to work either.

@pan64
It is a text file, a shell script. The first line reads;

Code:
#!/bin/sh
and the permissions are fine.

bamboozled.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding sth. to all users' PATH variable (sudo included) tpresa Linux - Software 2 08-03-2010 03:16 PM
Adding a executable file $PATH Variable ajeet@linux Solaris / OpenSolaris 3 03-18-2010 12:30 PM
Add path to $PATH variable alaios SUSE / openSUSE 2 04-19-2009 08:41 AM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 05:48 PM
Adding JavaVM to PATH variable? Crickit Linux - Software 3 05-06-2003 03:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration