How to set, permanently, my own directory instead of /home/bin in $PATH in ubuntu? [duplicate]
This question already has an answer here:
How to add a directory to the PATH?
17 answers
This might be a repeated question, but I couldn't relate to any previous answer. I basically want to run my shell-script from anywhere in ubuntu 16.04 (whether I'm inside the directory where the shell-script is placed or not).
I know the first method which is to place the shell-script inside the /home/user/bin directory (that is already set in the $PATH), change the shell-script permission mode and, finally, reset the bash by re-starting the terminal. This way everything worked fine.
But, since I want to learn how to set the environment myself, instead of using /home/user/bin I would like to use my own created directory.
So, I placed my shell-script inside a newly created /home/workspace/myproject/bin directory and, of course, I changed its mode. Then run the following command:
echo $PATH
Then, amended the $PATH variable as follow:
PATH="/echo/command/result:/home/workspace/myproject/bin"
Then, set the environment:
source /etc/environment && export PATH
But it doesn't work !
UPDATE
I know I could also do it through editing the ~/.profile file. But my aim is to do it directly from the terminal without having to open and edit a file. And you can see why, using only two commands in a row, immediately after finishing writing the shell-script, is much faster, right ?
To be clear: I want to know why resetting of the /etc/environment didn't work?
command-line bash scripts paths
marked as duplicate by dessert
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 13 at 18:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to add a directory to the PATH?
17 answers
This might be a repeated question, but I couldn't relate to any previous answer. I basically want to run my shell-script from anywhere in ubuntu 16.04 (whether I'm inside the directory where the shell-script is placed or not).
I know the first method which is to place the shell-script inside the /home/user/bin directory (that is already set in the $PATH), change the shell-script permission mode and, finally, reset the bash by re-starting the terminal. This way everything worked fine.
But, since I want to learn how to set the environment myself, instead of using /home/user/bin I would like to use my own created directory.
So, I placed my shell-script inside a newly created /home/workspace/myproject/bin directory and, of course, I changed its mode. Then run the following command:
echo $PATH
Then, amended the $PATH variable as follow:
PATH="/echo/command/result:/home/workspace/myproject/bin"
Then, set the environment:
source /etc/environment && export PATH
But it doesn't work !
UPDATE
I know I could also do it through editing the ~/.profile file. But my aim is to do it directly from the terminal without having to open and edit a file. And you can see why, using only two commands in a row, immediately after finishing writing the shell-script, is much faster, right ?
To be clear: I want to know why resetting of the /etc/environment didn't work?
command-line bash scripts paths
marked as duplicate by dessert
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 13 at 18:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Your PATH statement is incorrect, and /etc/environment resets the path. Please see my answer. Please remember to accept it if it was helpful. Thanks!
– heynnema
Feb 13 at 18:04
Thanks for your reply, but why myPATHstatement is incorrect ?!
– McLan
Feb 14 at 13:57
1
When sourcing /etc/environment, it negates any path changes that you made, because it has an implicitPATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games". Much easier to edit ~/.profile once, than typing this in multiple times, as per my answer.
– heynnema
Feb 14 at 14:13
@heynnema : So basically I can't change that implicit PATH, can I ? [by the way, I want to learn how to do, not only necessary because it is easier]
– McLan
Feb 14 at 14:23
1
Then use just the PATH statement from my answer, nothing else.
– heynnema
Feb 14 at 14:24
add a comment |
This question already has an answer here:
How to add a directory to the PATH?
17 answers
This might be a repeated question, but I couldn't relate to any previous answer. I basically want to run my shell-script from anywhere in ubuntu 16.04 (whether I'm inside the directory where the shell-script is placed or not).
I know the first method which is to place the shell-script inside the /home/user/bin directory (that is already set in the $PATH), change the shell-script permission mode and, finally, reset the bash by re-starting the terminal. This way everything worked fine.
But, since I want to learn how to set the environment myself, instead of using /home/user/bin I would like to use my own created directory.
So, I placed my shell-script inside a newly created /home/workspace/myproject/bin directory and, of course, I changed its mode. Then run the following command:
echo $PATH
Then, amended the $PATH variable as follow:
PATH="/echo/command/result:/home/workspace/myproject/bin"
Then, set the environment:
source /etc/environment && export PATH
But it doesn't work !
UPDATE
I know I could also do it through editing the ~/.profile file. But my aim is to do it directly from the terminal without having to open and edit a file. And you can see why, using only two commands in a row, immediately after finishing writing the shell-script, is much faster, right ?
To be clear: I want to know why resetting of the /etc/environment didn't work?
command-line bash scripts paths
This question already has an answer here:
How to add a directory to the PATH?
17 answers
This might be a repeated question, but I couldn't relate to any previous answer. I basically want to run my shell-script from anywhere in ubuntu 16.04 (whether I'm inside the directory where the shell-script is placed or not).
I know the first method which is to place the shell-script inside the /home/user/bin directory (that is already set in the $PATH), change the shell-script permission mode and, finally, reset the bash by re-starting the terminal. This way everything worked fine.
But, since I want to learn how to set the environment myself, instead of using /home/user/bin I would like to use my own created directory.
So, I placed my shell-script inside a newly created /home/workspace/myproject/bin directory and, of course, I changed its mode. Then run the following command:
echo $PATH
Then, amended the $PATH variable as follow:
PATH="/echo/command/result:/home/workspace/myproject/bin"
Then, set the environment:
source /etc/environment && export PATH
But it doesn't work !
UPDATE
I know I could also do it through editing the ~/.profile file. But my aim is to do it directly from the terminal without having to open and edit a file. And you can see why, using only two commands in a row, immediately after finishing writing the shell-script, is much faster, right ?
To be clear: I want to know why resetting of the /etc/environment didn't work?
This question already has an answer here:
How to add a directory to the PATH?
17 answers
command-line bash scripts paths
command-line bash scripts paths
edited Feb 14 at 14:08
McLan
asked Feb 13 at 16:05
McLanMcLan
1671110
1671110
marked as duplicate by dessert
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 13 at 18:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by dessert
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 13 at 18:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Your PATH statement is incorrect, and /etc/environment resets the path. Please see my answer. Please remember to accept it if it was helpful. Thanks!
– heynnema
Feb 13 at 18:04
Thanks for your reply, but why myPATHstatement is incorrect ?!
– McLan
Feb 14 at 13:57
1
When sourcing /etc/environment, it negates any path changes that you made, because it has an implicitPATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games". Much easier to edit ~/.profile once, than typing this in multiple times, as per my answer.
– heynnema
Feb 14 at 14:13
@heynnema : So basically I can't change that implicit PATH, can I ? [by the way, I want to learn how to do, not only necessary because it is easier]
– McLan
Feb 14 at 14:23
1
Then use just the PATH statement from my answer, nothing else.
– heynnema
Feb 14 at 14:24
add a comment |
1
Your PATH statement is incorrect, and /etc/environment resets the path. Please see my answer. Please remember to accept it if it was helpful. Thanks!
– heynnema
Feb 13 at 18:04
Thanks for your reply, but why myPATHstatement is incorrect ?!
– McLan
Feb 14 at 13:57
1
When sourcing /etc/environment, it negates any path changes that you made, because it has an implicitPATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games". Much easier to edit ~/.profile once, than typing this in multiple times, as per my answer.
– heynnema
Feb 14 at 14:13
@heynnema : So basically I can't change that implicit PATH, can I ? [by the way, I want to learn how to do, not only necessary because it is easier]
– McLan
Feb 14 at 14:23
1
Then use just the PATH statement from my answer, nothing else.
– heynnema
Feb 14 at 14:24
1
1
Your PATH statement is incorrect, and /etc/environment resets the path. Please see my answer. Please remember to accept it if it was helpful. Thanks!
– heynnema
Feb 13 at 18:04
Your PATH statement is incorrect, and /etc/environment resets the path. Please see my answer. Please remember to accept it if it was helpful. Thanks!
– heynnema
Feb 13 at 18:04
Thanks for your reply, but why my
PATH statement is incorrect ?!– McLan
Feb 14 at 13:57
Thanks for your reply, but why my
PATH statement is incorrect ?!– McLan
Feb 14 at 13:57
1
1
When sourcing /etc/environment, it negates any path changes that you made, because it has an implicit
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games". Much easier to edit ~/.profile once, than typing this in multiple times, as per my answer.– heynnema
Feb 14 at 14:13
When sourcing /etc/environment, it negates any path changes that you made, because it has an implicit
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games". Much easier to edit ~/.profile once, than typing this in multiple times, as per my answer.– heynnema
Feb 14 at 14:13
@heynnema : So basically I can't change that implicit PATH, can I ? [by the way, I want to learn how to do, not only necessary because it is easier]
– McLan
Feb 14 at 14:23
@heynnema : So basically I can't change that implicit PATH, can I ? [by the way, I want to learn how to do, not only necessary because it is easier]
– McLan
Feb 14 at 14:23
1
1
Then use just the PATH statement from my answer, nothing else.
– heynnema
Feb 14 at 14:24
Then use just the PATH statement from my answer, nothing else.
– heynnema
Feb 14 at 14:24
add a comment |
1 Answer
1
active
oldest
votes
Add this to the end of your ~/.profile
It checks to see if the directory exists, and if it does, then it adds it to the existing path.
# set PATH so it includes user's private /workspace/myproject/bin if it exists
if [ -d "$HOME/workspace/myproject/bin" ] ; then
PATH="$HOME/workspace/myproject/bin:$PATH"
fi
then log out, and log back in.
But I don't want to go inside the ~/.profile and edit it. Instead, I want to be able to do it from the command line the way I mentioned in my question (resetting the `/etc/environemnt'. However, your answer is useful, even though it doesn't exactly fit what I am looking for. But, since it was the reason why I updated the question, I'll be very happy to give a thumbs up.
– McLan
Feb 14 at 14:19
1
@McLan then just use the PATH statement shown above, nothing else.
– heynnema
Feb 14 at 14:21
Well, thatPATHstatement partially worked. As once the current terminal is closed, the same command needs to be executed again in the new terminal. Again, even if I put it in the~/.profile, I need tosourcethe file everytime i open a new terminal. I need a permenant solution whether I restart the terminal or reboot the machine !
– McLan
Feb 14 at 14:42
2
@McLan Yes, the PATH command is temporary, but you asked how to do it manually via CLI. Either you edit ~/.profile, or /etc/environment... but changes to /etc/environment effect ALL users, not just yours. And you don't need to source ~/.profile, cause it gets executed at login time. That's the correct permanent solution for you.
– heynnema
Feb 14 at 14:46
1
@McLan as I mentioned earlier, it's just easier to drop your project script into ~/bin, and be done with it. That path already exists. That's what it's for.
– heynnema
Feb 14 at 14:58
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Add this to the end of your ~/.profile
It checks to see if the directory exists, and if it does, then it adds it to the existing path.
# set PATH so it includes user's private /workspace/myproject/bin if it exists
if [ -d "$HOME/workspace/myproject/bin" ] ; then
PATH="$HOME/workspace/myproject/bin:$PATH"
fi
then log out, and log back in.
But I don't want to go inside the ~/.profile and edit it. Instead, I want to be able to do it from the command line the way I mentioned in my question (resetting the `/etc/environemnt'. However, your answer is useful, even though it doesn't exactly fit what I am looking for. But, since it was the reason why I updated the question, I'll be very happy to give a thumbs up.
– McLan
Feb 14 at 14:19
1
@McLan then just use the PATH statement shown above, nothing else.
– heynnema
Feb 14 at 14:21
Well, thatPATHstatement partially worked. As once the current terminal is closed, the same command needs to be executed again in the new terminal. Again, even if I put it in the~/.profile, I need tosourcethe file everytime i open a new terminal. I need a permenant solution whether I restart the terminal or reboot the machine !
– McLan
Feb 14 at 14:42
2
@McLan Yes, the PATH command is temporary, but you asked how to do it manually via CLI. Either you edit ~/.profile, or /etc/environment... but changes to /etc/environment effect ALL users, not just yours. And you don't need to source ~/.profile, cause it gets executed at login time. That's the correct permanent solution for you.
– heynnema
Feb 14 at 14:46
1
@McLan as I mentioned earlier, it's just easier to drop your project script into ~/bin, and be done with it. That path already exists. That's what it's for.
– heynnema
Feb 14 at 14:58
|
show 1 more comment
Add this to the end of your ~/.profile
It checks to see if the directory exists, and if it does, then it adds it to the existing path.
# set PATH so it includes user's private /workspace/myproject/bin if it exists
if [ -d "$HOME/workspace/myproject/bin" ] ; then
PATH="$HOME/workspace/myproject/bin:$PATH"
fi
then log out, and log back in.
But I don't want to go inside the ~/.profile and edit it. Instead, I want to be able to do it from the command line the way I mentioned in my question (resetting the `/etc/environemnt'. However, your answer is useful, even though it doesn't exactly fit what I am looking for. But, since it was the reason why I updated the question, I'll be very happy to give a thumbs up.
– McLan
Feb 14 at 14:19
1
@McLan then just use the PATH statement shown above, nothing else.
– heynnema
Feb 14 at 14:21
Well, thatPATHstatement partially worked. As once the current terminal is closed, the same command needs to be executed again in the new terminal. Again, even if I put it in the~/.profile, I need tosourcethe file everytime i open a new terminal. I need a permenant solution whether I restart the terminal or reboot the machine !
– McLan
Feb 14 at 14:42
2
@McLan Yes, the PATH command is temporary, but you asked how to do it manually via CLI. Either you edit ~/.profile, or /etc/environment... but changes to /etc/environment effect ALL users, not just yours. And you don't need to source ~/.profile, cause it gets executed at login time. That's the correct permanent solution for you.
– heynnema
Feb 14 at 14:46
1
@McLan as I mentioned earlier, it's just easier to drop your project script into ~/bin, and be done with it. That path already exists. That's what it's for.
– heynnema
Feb 14 at 14:58
|
show 1 more comment
Add this to the end of your ~/.profile
It checks to see if the directory exists, and if it does, then it adds it to the existing path.
# set PATH so it includes user's private /workspace/myproject/bin if it exists
if [ -d "$HOME/workspace/myproject/bin" ] ; then
PATH="$HOME/workspace/myproject/bin:$PATH"
fi
then log out, and log back in.
Add this to the end of your ~/.profile
It checks to see if the directory exists, and if it does, then it adds it to the existing path.
# set PATH so it includes user's private /workspace/myproject/bin if it exists
if [ -d "$HOME/workspace/myproject/bin" ] ; then
PATH="$HOME/workspace/myproject/bin:$PATH"
fi
then log out, and log back in.
edited Feb 13 at 18:06
answered Feb 13 at 17:59
heynnemaheynnema
20.5k22258
20.5k22258
But I don't want to go inside the ~/.profile and edit it. Instead, I want to be able to do it from the command line the way I mentioned in my question (resetting the `/etc/environemnt'. However, your answer is useful, even though it doesn't exactly fit what I am looking for. But, since it was the reason why I updated the question, I'll be very happy to give a thumbs up.
– McLan
Feb 14 at 14:19
1
@McLan then just use the PATH statement shown above, nothing else.
– heynnema
Feb 14 at 14:21
Well, thatPATHstatement partially worked. As once the current terminal is closed, the same command needs to be executed again in the new terminal. Again, even if I put it in the~/.profile, I need tosourcethe file everytime i open a new terminal. I need a permenant solution whether I restart the terminal or reboot the machine !
– McLan
Feb 14 at 14:42
2
@McLan Yes, the PATH command is temporary, but you asked how to do it manually via CLI. Either you edit ~/.profile, or /etc/environment... but changes to /etc/environment effect ALL users, not just yours. And you don't need to source ~/.profile, cause it gets executed at login time. That's the correct permanent solution for you.
– heynnema
Feb 14 at 14:46
1
@McLan as I mentioned earlier, it's just easier to drop your project script into ~/bin, and be done with it. That path already exists. That's what it's for.
– heynnema
Feb 14 at 14:58
|
show 1 more comment
But I don't want to go inside the ~/.profile and edit it. Instead, I want to be able to do it from the command line the way I mentioned in my question (resetting the `/etc/environemnt'. However, your answer is useful, even though it doesn't exactly fit what I am looking for. But, since it was the reason why I updated the question, I'll be very happy to give a thumbs up.
– McLan
Feb 14 at 14:19
1
@McLan then just use the PATH statement shown above, nothing else.
– heynnema
Feb 14 at 14:21
Well, thatPATHstatement partially worked. As once the current terminal is closed, the same command needs to be executed again in the new terminal. Again, even if I put it in the~/.profile, I need tosourcethe file everytime i open a new terminal. I need a permenant solution whether I restart the terminal or reboot the machine !
– McLan
Feb 14 at 14:42
2
@McLan Yes, the PATH command is temporary, but you asked how to do it manually via CLI. Either you edit ~/.profile, or /etc/environment... but changes to /etc/environment effect ALL users, not just yours. And you don't need to source ~/.profile, cause it gets executed at login time. That's the correct permanent solution for you.
– heynnema
Feb 14 at 14:46
1
@McLan as I mentioned earlier, it's just easier to drop your project script into ~/bin, and be done with it. That path already exists. That's what it's for.
– heynnema
Feb 14 at 14:58
But I don't want to go inside the ~/.profile and edit it. Instead, I want to be able to do it from the command line the way I mentioned in my question (resetting the `/etc/environemnt'. However, your answer is useful, even though it doesn't exactly fit what I am looking for. But, since it was the reason why I updated the question, I'll be very happy to give a thumbs up.
– McLan
Feb 14 at 14:19
But I don't want to go inside the ~/.profile and edit it. Instead, I want to be able to do it from the command line the way I mentioned in my question (resetting the `/etc/environemnt'. However, your answer is useful, even though it doesn't exactly fit what I am looking for. But, since it was the reason why I updated the question, I'll be very happy to give a thumbs up.
– McLan
Feb 14 at 14:19
1
1
@McLan then just use the PATH statement shown above, nothing else.
– heynnema
Feb 14 at 14:21
@McLan then just use the PATH statement shown above, nothing else.
– heynnema
Feb 14 at 14:21
Well, that
PATH statement partially worked. As once the current terminal is closed, the same command needs to be executed again in the new terminal. Again, even if I put it in the ~/.profile, I need to source the file everytime i open a new terminal. I need a permenant solution whether I restart the terminal or reboot the machine !– McLan
Feb 14 at 14:42
Well, that
PATH statement partially worked. As once the current terminal is closed, the same command needs to be executed again in the new terminal. Again, even if I put it in the ~/.profile, I need to source the file everytime i open a new terminal. I need a permenant solution whether I restart the terminal or reboot the machine !– McLan
Feb 14 at 14:42
2
2
@McLan Yes, the PATH command is temporary, but you asked how to do it manually via CLI. Either you edit ~/.profile, or /etc/environment... but changes to /etc/environment effect ALL users, not just yours. And you don't need to source ~/.profile, cause it gets executed at login time. That's the correct permanent solution for you.
– heynnema
Feb 14 at 14:46
@McLan Yes, the PATH command is temporary, but you asked how to do it manually via CLI. Either you edit ~/.profile, or /etc/environment... but changes to /etc/environment effect ALL users, not just yours. And you don't need to source ~/.profile, cause it gets executed at login time. That's the correct permanent solution for you.
– heynnema
Feb 14 at 14:46
1
1
@McLan as I mentioned earlier, it's just easier to drop your project script into ~/bin, and be done with it. That path already exists. That's what it's for.
– heynnema
Feb 14 at 14:58
@McLan as I mentioned earlier, it's just easier to drop your project script into ~/bin, and be done with it. That path already exists. That's what it's for.
– heynnema
Feb 14 at 14:58
|
show 1 more comment
1
Your PATH statement is incorrect, and /etc/environment resets the path. Please see my answer. Please remember to accept it if it was helpful. Thanks!
– heynnema
Feb 13 at 18:04
Thanks for your reply, but why my
PATHstatement is incorrect ?!– McLan
Feb 14 at 13:57
1
When sourcing /etc/environment, it negates any path changes that you made, because it has an implicit
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games". Much easier to edit ~/.profile once, than typing this in multiple times, as per my answer.– heynnema
Feb 14 at 14:13
@heynnema : So basically I can't change that implicit PATH, can I ? [by the way, I want to learn how to do, not only necessary because it is easier]
– McLan
Feb 14 at 14:23
1
Then use just the PATH statement from my answer, nothing else.
– heynnema
Feb 14 at 14:24