LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Slackware- Help installing a permanent path (http://www.linuxquestions.org/questions/slackware-14/slackware-help-installing-a-permanent-path-4175459958/)

PeterUK 04-29-2013 02:50 AM

Slackware- Help installing a permanent path
 
Hi!

I would like to get a path added permanently:

At the moment I add the path by

export PATH=$PATH:/path/

and it works but I need to do every time I open a terminal window.

I did looked at the etc/profile but it looked rather a long file and I am not sure where to put it.

Also I've read some post and did man bash and look and it say It will load some files like .profile .bash* but there are not in etc.

Are they in another directory?

Also from the post say profile file is only load it when you log in so maybe I rather have .bash which it should be loaded every time I open a terminal, right? But I cannot find that file.

wildwizard 04-29-2013 02:56 AM

If you go right to the bottom of the bash man page you will see the list of files it uses and when and where they should be.

The file you probably want is ~/.bashrc

This file will not exist until you create it, so that is why you don't see anything now in fact none of the per user files will exist as they are only required for user specific settings.

PeterUK 04-29-2013 03:47 AM

Quote:

Originally Posted by wildwizard (Post 4940946)
If you go right to the bottom of the bash man page you will see the list of files it uses and when and where they should be.

The file you probably want is ~/.bashrc

This file will not exist until you create it, so that is why you don't see anything now in fact none of the per user files will exist as they are only required for user specific settings.

Thank you!

that is right I didnt really know where was ~/ so I did cd ~/ found out that is root dir.

So I went and follow your advice and look at the bash doc and read for bashrc it looks ok so I did create a file in root folder with this content:

# Set the adding path $PATH:
PATH="/home/to/scripts"

And now every time I open the terminal its working! :-)

Thanks!

I am going to leave the thread open for a bit to see if anyone has input about the content in the .bashrc file.

Bazzaah 04-29-2013 04:14 AM

~/ is just a shorthand for referring to your current user's home directory. If you are logged in as root (and you shouldn't be) ~/ will take you to root's home directory. If you are logged in as your user, ~/ will take you to your user's home directory (i.e. /home/user).

Your .bashrc should be in your user's home directory. I am assuming here that you do not log in as root and that you created a user account when you installed Slackware.

PeterUK 04-29-2013 05:13 AM

Quote:

Originally Posted by Bazzaah (Post 4940981)
~/ is just a shorthand for referring to your current user's home directory. If you are logged in as root (and you shouldn't be) ~/ will take you to root's home directory. If you are logged in as your user, ~/ will take you to your user's home directory (i.e. /home/user).

Your .bashrc should be in your user's home directory. I am assuming here that you do not log in as root and that you created a user account when you installed Slackware.

Thanks!

I know I keep looking at advice that should not be longed in as root, But I did create the user but I have not being using it.

I know I should, last weekend look at root folder and I realize that my user folder should have looked like that! :-/

But I like the ability to put/edit files into the system folder without have to look into a terminal or keep typing my root password or getting message I dont have permission for this or for that.

Can this sorted by having a way to start the file management system, and perhaps a terminal as root too. I know in mu Ubuntu machine I could have done su and then all was as root.

I just think it complicate more the administration of the machine, plus you sometime have to be dealing with group permission and all that. I know is wrong but in a way make things easier and faster to do it.

Bazzaah 04-29-2013 05:39 AM

Quote:

Originally Posted by PeterUK (Post 4941012)
Thanks!

I know I keep looking at advice that should not be longed in as root, But I did create the user but I have not being using it.

I know I should, last weekend look at root folder and I realize that my user folder should have looked like that! :-/

But I like the ability to put/edit files into the system folder without have to look into a terminal or keep typing my root password or getting message I dont have permission for this or for that.

Can this sorted by having a way to start the file management system, and perhaps a terminal as root too. I know in mu Ubuntu machine I could have done su and then all was as root.

I just think it complicate more the administration of the machine, plus you sometime have to be dealing with group permission and all that. I know is wrong but in a way make things easier and faster to do it.

It's not a great idea to be logged in as root permanently. You can easily break your system and put your important data at risk. Up to you of course but I doubt you'd find anyone on here who thinks that logging in as root is a good idea.

It's no real effort to use su or su - or sudo and I would suggest that you use your user account and one of those when you need elevated privileges. But, as I say, it's up to you.

wildwizard 04-29-2013 05:41 AM

Some terminology and other hints :-

/root (root's home dir) you should call it root's home directory and not the root dir as the 2 are not always the same thing
/ this is the root directory

On some UNiX systems past root's home dir and / were the one and the same, but they aren't in Linux so you should call them accordingly

the command "cd" without any parameters is the same as "cd ~" (shortcuts are good)

You will also note the when you're in your home dir that the command prompt changes

in my home dir :-
michael@indigo:~$

in /home (type "cd .." from your home dir and watch the change)
michael@indigo:/home$

The ~ is the shorthand for the complete path which is /home/michael

Slackware also has su, anytime you need to access root you can just type it in and voila your root.

Not sure why you need to be root all the time, I rarely have the need for it outside of system updates.

brianL 04-29-2013 06:25 AM

PeterUK
I really think you need to do some reading about running Slackware, have a look here:

http://docs.slackware.com/toc:start

psionl0 04-29-2013 06:38 AM

Quote:

Originally Posted by PeterUK (Post 4941012)
But I like the ability to put/edit files into the system folder without have to look into a terminal or keep typing my root password or getting message I dont have permission for this or for that.

That's poor practice.

You should never mess around with system files unless you are doing it via a package management system. Otherwise you won't be able to keep track of it. If you ever upgrade or have to reinstall Slackware, the odds are that you will never get it working as well as you had it before.

PeterUK 04-29-2013 06:40 AM

Quote:

Originally Posted by brianL (Post 4941053)
PeterUK
I really think you need to do some reading about running Slackware, have a look here:

http://docs.slackware.com/toc:start

That is a lot to read! :-/

Thanks for the tip! I know there is a lot to learn but hey I cannot do it all in one day! :-(

PeterUK 04-29-2013 06:48 AM

Quote:

Originally Posted by wildwizard (Post 4941028)
Some terminology and other hints :-

/root (root's home dir) you should call it root's home directory and not the root dir as the 2 are not always the same thing
/ this is the root directory

On some UNiX systems past root's home dir and / were the one and the same, but they aren't in Linux so you should call them accordingly

the command "cd" without any parameters is the same as "cd ~" (shortcuts are good)

You will also note the when you're in your home dir that the command prompt changes

in my home dir :-
michael@indigo:~$

in /home (type "cd .." from your home dir and watch the change)
michael@indigo:/home$

The ~ is the shorthand for the complete path which is /home/michael

Slackware also has su, anytime you need to access root you can just type it in and voila your root.

Not sure why you need to be root all the time, I rarely have the need for it outside of system updates.

I'm coming from 10.04 I remember I keep typing my root password and sometime I have to look for some terminal command here and there on the net.

lately I was thinking on switch to the user account but for the only reason that the files say owner root, and there were pulled from the back up and there was a user now I am not sure if I am going to have problem with permission issues?

brianL 04-29-2013 06:54 AM

Quote:

Originally Posted by PeterUK (Post 4941065)
That is a lot to read! :-/

Thanks for the tip! I know there is a lot to learn but hey I cannot do it all in one day! :-(

I wouldn't expect you to. :)
Read any relevant bits as and when you need to.

tronayne 04-29-2013 07:13 AM

There are a couple of ways to set the PATH environment variable: system-wide and individual user.

System-wide is exactly what it sounds like: any user logging in on the system will receive the setting; individual user, on the other hand, is only set for specific users.

There is a directory, /etc/profile.d. In there are files that are executed at log in for every user (including the root user). You can create a file in /etc/profile.d for system-wide use (but you would not do so for a specialized, individual user).

Here's an example: I have an application, the Generic Mapping Tools, or GMT, that is used to manipulate geographic data sets and, you know, draw maps. Because GMT is optional software (and it's big) I install in the /opt directory; /opt is not on any user PATH, so I need to add it system-wide (so anybody can use it). I do that in /etc/profile.d with this file, named gmt.sh:
Code:

cat /etc/profile.d/gmt.sh
#!/bin/sh

export GMTHOME="/opt/GMT"
export NETCDFHOME="/opt/netCDF"
export MANPATH="${MANPATH}:${GMTHOME}/man"
export MANPATH="${MANPATH}:${NETCDFHOME}/man"
# Set the local system $PATH:
PATH="${PATH}:${GMTHOME}/bin"
PATH="${PATH}:${NETCDFHOME}/bin"

Translated, the above defines GMTHOME and NETCDFHOME (netCDF is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data used by GMT) then uses those tokens to add paths to the manual pages and the bin directories for both GMT and netCDF. Whenever any user logs in, those PATHs are set in their shell environment.

To add a file like this to /etc/profile.d, you must be root (but use su - to become root, don't log in as root as normal practice) and create the file with a text editor (vi, vim, emacs, whatever):
Code:

log in as you
su -
<enter the root password>
cd /etc/profile.d
vi gmt.sh
<type the lines>
ZZ        <save the file>
chmod 755 gmt.sh
Ctrl-D    <exit from su ->

The file must be executable, thus the chmod 755 gmt.sh.

That's it, log out, log back in, then
Code:

echo ${GMTHOME}
/opt/GMT

That will show you that you did it right.

You can do the same thing for individual users by adding the above lines (don't include the #!/bin/sh though) in the user's home directory .profile or .bash_profile or .bashrc.

I prefer .profile or .bash_profile, which is executed at log in (/etc/profile and the content of /etc/profile.d are executed at log in to set user environment variables). .bashrc, on the other hand, is executed for interactive non-log in shells.

Hope this helps some.

PeterUK 04-30-2013 12:14 PM

Quote:

Originally Posted by tronayne (Post 4941093)
There are a couple of ways to set the PATH environment variable: system-wide and individual user.

System-wide is exactly what it sounds like: any user logging in on the system will receive the setting; individual user, on the other hand, is only set for specific users.

There is a directory, /etc/profile.d. In there are files that are executed at log in for every user (including the root user). You can create a file in /etc/profile.d for system-wide use (but you would not do so for a specialized, individual user).

Here's an example: I have an application, the Generic Mapping Tools, or GMT, that is used to manipulate geographic data sets and, you know, draw maps. Because GMT is optional software (and it's big) I install in the /opt directory; /opt is not on any user PATH, so I need to add it system-wide (so anybody can use it). I do that in /etc/profile.d with this file, named gmt.sh:
Code:

cat /etc/profile.d/gmt.sh
#!/bin/sh

export GMTHOME="/opt/GMT"
export NETCDFHOME="/opt/netCDF"
export MANPATH="${MANPATH}:${GMTHOME}/man"
export MANPATH="${MANPATH}:${NETCDFHOME}/man"
# Set the local system $PATH:
PATH="${PATH}:${GMTHOME}/bin"
PATH="${PATH}:${NETCDFHOME}/bin"

Translated, the above defines GMTHOME and NETCDFHOME (netCDF is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data used by GMT) then uses those tokens to add paths to the manual pages and the bin directories for both GMT and netCDF. Whenever any user logs in, those PATHs are set in their shell environment.

To add a file like this to /etc/profile.d, you must be root (but use su - to become root, don't log in as root as normal practice) and create the file with a text editor (vi, vim, emacs, whatever):
Code:

log in as you
su -
<enter the root password>
cd /etc/profile.d
vi gmt.sh
<type the lines>
ZZ        <save the file>
chmod 755 gmt.sh
Ctrl-D    <exit from su ->

The file must be executable, thus the chmod 755 gmt.sh.

That's it, log out, log back in, then
Code:

echo ${GMTHOME}
/opt/GMT

That will show you that you did it right.

You can do the same thing for individual users by adding the above lines (don't include the #!/bin/sh though) in the user's home directory .profile or .bash_profile or .bashrc.

I prefer .profile or .bash_profile, which is executed at log in (/etc/profile and the content of /etc/profile.d are executed at log in to set user environment variables). .bashrc, on the other hand, is executed for interactive non-log in shells.

Hope this helps some.

Today I try to type a command and it will not work, so in order to get it going again I have to remove the .bashrc file I created. When I have time I will try to approach or file all those path to be added to my bashrc file. :-(


All times are GMT -5. The time now is 05:14 AM.