Linux $PATH variable autoupdates - linux

I have a problem on my Ubuntu 18.04 , I set PATH variable , and it works fine but after some time it reverts my changes. I do something like:
export $PATH=$PATH:/my/dir/bin .

You could add it to your .bashrc, and make it permanent.
Using any text editor, edit ~/.bashrc, and add the line you need.
Then source it, source ~/.bashrc.

With the export command the new PATH variable will be only available at the current terminal session. To make it permanent over the different sessions you will need to add it to the ~/.bashrc file.

That call will only work for your terminal session, you need to edit your ~/.profile or ~/.bashrc file, and put the path in there then start a new terminal session

Related

Environment variable PATH on linux

Hi i am currently trying to set keywords for my terminal to launch some software without having to type the whole path.
For exemple:
firefox
#instead of
/home/debian/firefox/firefox
I always do this kind of thing on windows by setting path in the environment variable manager.
After i read this post PATH environment variable in linux , i added this line to the etc/environment file:
export firefox=/home/debian/firefox/firefox
#I also tried this:
export PATH=$PATH:/home/debian/firefox
It doesn't work, can someone explains me how to do this?
I would setup a new alias in my .bashrc or .profile, which should be located under your home directory. Add the following to the end of the file:
alias firefox="/home/debian/firefox/firefox"
Save the file and reload it using:
source ~/.bashrc
Since you added the alias to your .bashrc this alias will be created everytime you open a new instance of a shell.
You could use nohup to keep the command running after the shell session ends:
alias firefox="nohup /home/debian/firefox/firefox &"
Notice the trailing & character, which will run the command in the background so you can keep using your terminal.
You can also make an alias in your .bashrc file.
$ vim ~/.bashrc
It will open your .bashrc in read mode. Get in write mode by pressing i. You can create alias at anywhere in the file or below already created alias list.
alias firefox='/home/debian/firefox/firefox'
press Esc and then :wq
This will create your alias, save and exit the file. Now you only have to compile .bashrc by this
$ source ~/.bashrc
After this you can only have to use firefox instead of long /home/debian/firefox/firefox
Adding /home/debian/firefox to your PATH should have done it.
Did you start a new shell after making that change? Otherwise the new PATH would not have exported yet. Alternatively, you can just run export PATH=$PATH:/home/debian/firefox directly to update it for your current session.

How to not print the path in user#user:path$ in my terminal

When I'm working inside a directory in my console, this line
user#user:/a/very/very/very/very/long/path$ is disturbing me. Is there a way to minimize or delete the path from the console.
Simply export the PS1 env variable to what you want to display, example :
export PS1='$(whoami)#$(hostname):'
If you want this to be permanent, make sure to configure it in $HOME/.bashrc or $HOME/.bash_profile.
Configure the $PS1 variable to your liking. See PROMPTING in man bash for details. For example, using \W instead of \w would show only the name of the current directory, not the whole path.
export PS1='\u#\h:\W\$'
Save the line to your ~/.bashrc or ~/.bash_profile to apply the configuration to every newly started session.

Add a command for bash script to terminal

I have studio.sh file in my android-studio/bin folder, which I would like to use as a command in bash (like launching any other normal application).
I read somewhere that adding this line to ~/.profile should work,
export PATH=$PATH:/home/goel/android-studio/bin
But it doesn't work. Whats the correct process?
Add the script folder name to PATH environment variable in ~/bash.rc file
and you can also create alias for you script in ~/bash.rc
and source the /etc/bash.bashrc file, now you can issue your script or alias name in any terminal. Hope this helps.
If you change your PATH in a .profile, you still have to make the shell read the .profile. Starting a new terminal is sometimes not enough (some terminals don't read the .profile), in which case you have to log out and back in.
Is studio.sh executable? Have you tried ./studio.sh inside its containing folder to check whether it runs at all?

Cannot create permanant environment variable in Ubuntu

I'm trying to create a permanent environment variable on Ubuntu.
I tried the following:
export SASS_LIBSASS_PATH=/usr/local/lib/libsass
When I opened a new terminal and used 'printenv', I found the variable disappeared!
I also tried to make it work by appending:
SASS_LIBSASS_PATH="/usr/local/lib/libsass"
to the end of the file in /etc/environment, and then used:
source /etc/enviroment
That did not work!
UPDATE:
I then tried editing my ~/.profile file:
SASS_LIBSASS_PATH="/usr/local/lib/libsass"
that did not work.
I then tried instead appending the following at the end of ~/.profile file:
export SASS_LIBSASS_PATH="/usr/local/lib/libsass"
that too did not work!
How can I make a permanent system variable?
export only sets the environment variable in your current shell session and any child processes started by that shell session. It is certainly not "permanent". The only way to set an environment variable for future shell sessions is to add the export command to a shell start-up file. Your best bet is probably to put it in ~/.profile (unless the file ~/.bash_profile exists).

How to add in bash for auto completion of arcanist commands

I am new to linux.
I am trying to set up arcanist.
I am done with git clone and adding the path in environment variable, however I am confused on how to set up the tab completion for arcanist commands.
In the arcanist user guide it says that you need to add source /path/to/arcanist/resources/shell/bash-completion to your .bashrc, .profile files.
What are these files and how can I edit them to work with arcanist with the tab completion.
The .bashrc, found in your home directory, is the configuration file for that user for bash.
There is a global bashrc usually located in /etc/bashrc.
The difference to .profile is that the .bashrc is executed every time you start a terminal (bash) while .profile only once when you use a login shell.
The command source loads everything that is inside the file you use with that command and treats it as if you wrote those commands in the .bashrc yourself. I guess in /path/to/arcanist/resources/shell/bash-completion are aliases/functions/etc. which enable tab-completion with arcanist.
Edit: for bash, the profile file is usually called .bash_profile.
After lot of googling and asking people, I finally did it.
First of all I had to export the path where my arcanist code from the github has been cloned in the ~/.bashsrc file(in bold below)
export PATH="$PATH:$HOME/.rvm/bin:$HOME/arcanist/bin/"
After this command, I copied the function which was present in the /arcanist/resources/shell/bash-completion into the bashrc file
And then I closed and open the terminal and bingo I was able to get arc and it's command as auto completion on striking tab.
Thanks ap0 for the comments.

Resources