Adding path variable in wsl - path

I have added a path in bashrc, still, the command is not found. When tried in ubuntu it worked but not in WSL. Why this happen?.
export PATH=\wsl$\Ubuntu\usr\local\mbdyn\bin:$PATH
added same path in .bashrc
error: command not found
**Please see the attached image

As you have been told, the forward slash to use is / and if you use the command
PATH="$PATH:/folder/subfolder/"
that value will only last in the PATH for the duration of the session.
To include a value in the PATH permanently, edit the .bashrc file from your home
$ sudo vim ~/.bashrc
you add at the end
export PATH="$PATH:/folder/subfolder/"
you save and you will have that value in the PATH in each session

You will need to modify the PATH variable as follows:
PATH="$PATH:/usr/local/mbdyn/bin"

Related

Adding Windows Path back to WSL

I'm running Ubuntu20.04 using WSL2, and I'm rather new to linux. While setting up my environment, I messed up my $PATH, as it no longer includes all of the directories in my windows path. Whenever I open Ubuntu, the terminal spews a bunch of errors of this nature:
-bash: export: `Files/Intel/Intel(R)': not a valid identifier
This is one of many errors, one for each component of my windows path. I'm not sure where Windows appends to the linux PATH, so I'm not sure where to look to make the fix.
Edit: Per some of the comments and answers, I do modify the $PATH in my .bashrc, using the code below. Commenting out this code fixes my issue, but I'm not sure what's wrong with this:
function append_to_pathlist
{
# get pathlist into local pathlist (add : at end)
eval "temp_pathlist=\$$1:"
# remove new path from local pathlist if exists
temp_pathlist=${temp_pathlist//"$2:"}
# append new path to front of local pathlist
if [[ "${temp_pathlist}" == ":" ]]; then
temp_pathlist="$2"
else
temp_pathlist="$2:${temp_pathlist}"
fi
# set pathlist to local pathlist (remove : at end)
export $1=${temp_pathlist%":"}
}
# Set the ARCH environment variable
export ARCH="x86_64-ubuntu20_04"
append_to_pathlist PATH "/home/jbrzozo24/.local/bin"
#Add stow pkgs environment variable, and add it to path
export STOW_PKGS_GLOBAL_ROOT="/classes/ece4750/install/stow-pkgs"
export STOW_PKGS_GLOBAL_PREFIX="${STOW_PKGS_GLOBAL_ROOT}/${ARCH}"
append_to_pathlist PATH "${STOW_PKGS_GLOBAL_PREFIX}/bin"
#append_to_pathlist PATH "$/classes/ece4750/install/venv-pkgs/x86_64-ubuntu20_04/python2.7.12/bin"
#PKG CONFIG stu
append_to_pathlist PKG_CONFIG_PATH "${STOW_PKGS_GLOBAL_PREFIX}/share/pkgconfig"
append_to_pathlist PKG_CONFIG_PATH "${STOW_PKGS_GLOBAL_PREFIX}/lib/pkgconfig"
Windows passes environment variables internally when you start a new WSL process as shown in this article.
Probably some profile script is overwriting the initial PATH variable. This documentation explains how to use Win32 variables inside WSL and the options available:
-bash: export: `Files/Intel/Intel(R)': not a valid identifier
Other possibility part of your path variable containing a non-escaped space or especial characters. You can print your path at the beginning of your ~/.bashrc or ~/.profile to see where is the problem.

Extend $PATH variable in git bash under Windows

I'm trying to extend my $PATH variable in git bash (MinGW shell) by adding the following to the file ~/.bashrc
PATH=$PATH':/c/Program Files/maven/apache-maven-3.2.5/bin'
After I did this and restarted the bash it seems like that the $PATH variable was extended like expected:
$ echo $PATH
MANY_OTHER_PATHS:/c/Program Files/maven/apache-maven-3.2.5/bin
But I still cannot execute the programms in the given directory:
$ mvn
bash: mvn: command not found
What went wrong here? How do I extend the PATH variable correctly?
Here are two ideas.
You can have your path with double quote mark.
export PATH=$PATH:"/C/Program Files (x86)/apache-maven-3.3.3/bin"
Or, You can also make symbolic link for the directory.
ln -s "/C/Program Files (x86)/apache-maven-3.3.3/bin" ./mvnbin
export PATH=$PATH:/your-path/mvnbin
It works for me in mingw32 environment.
I needed to add something to my Git Bash path permanently each time I open it. It was Meld.exe path which can be added with:
export PATH=$PATH:"/C/Program Files (x86)/Meld/lib"
In order to execute this command each bash session, you need a ~/.bashrc file. Check if it already exists or create it using notepad ~/.bashrc or touch ~/.bashrc.
You can check where it is with:
echo ~
Open it and add the command that adds the PATH (first command in this response).
I hope you found this useful.
According to this SO post, you need to escape Program Files with quotes. git-bash $PATH cannot parse windows directory with space
Add PATH in Git Bash Permanently | Windows Only
Just in case you are still wondering how to add a path permanently in git bash here is the step-by-step process for Windows users:
Create .bashrc in user's root folder using the below command. It will open notepad and ask you to create the file, click yes.
notepad ~/.bashrc
Put the directory you want to add as below, for more than 1 items repeat the same format in next line:
export PATH=$PATH:"/c/folder/folder/"
Save the file and relaunch the bash.
Next launch will give you a warning like WARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile. but git bash will handle it by creating the required files.
SOME INSIGHTS
Git Bash doesn't fetch Window's environment PATH, it maintains its PATH separately in more like a Linux way.
You can run export PATH=$PATH:"/c/folder/folder/" in cmd to add a directory to path, but it will be only for the current session once you close the bash, it will be gone.
.bashrc is a shell script file that will be executed every time you launch a new git bash window. So you can add any type of bash command here. We simply added the export command to add our desired directory to PATH.

How to find the source of $PATH?

I'm using a Centos 7 server. I'm entering the command echo $PATH and trying to figure out where it's getting the path that it's putting out. The path doesn't match what's in my .bash_profile, and there is no .bashrc file. How do I find out where my current $PATH is being sourced from?
The Default values for .bashrc and $PATH are stored in files /etc/bashrc and /etc/profile. These files are used by shell and kernel for setting default values for proper functioning of the server.
I would advise not to change any values here, as it might cause abnormal behavior in the server.

How do you update your "HOMEBREW_TEMP" environmental variable?

I'm getting the following error when running "brew doctor":
Error: Your Cellar and TEMP directories are on different volumes.
OS X won't move relative symlinks across volumes unless the target file already
exists. Brews known to be affected by this are Git and Narwhal.
You should set the "HOMEBREW_TEMP" environmental variable to a suitable
directory on the same volume as your Cellar
How do I set this variable? And what should I set it to? I can't seem to find anything about this when googling.
You set your HOMEBREW_TEMP by editing your ~/.bash_profile and doing this:
export HOMEBREW_TEMP=/new/path
Then start a new shell.
Alternatively type that into any already open shell.
Google setting shell environment variables for further information.
I fixed this problem by setting the path of the temp folder manualy.
First i created a folder temp in /usr/local/ and then added the following to my zsh file nano ~/.zshrc
export HOMEBREW_TEMP=/usr/local/temp
Same problem occurred to me. I actually have configured separate disk in memory for /private/tmp. Hope that's why this error occurred.
To solve this issue, create a directory somewhere, like /usr/local/brew_temp
Then add following line to file ~/.profile. If file doesn't exist create that file
export HOMEBREW_TEMP=/usr/local/brew_temp
In each restart it will set the HOMEBREW_TEMP environment variable to that path. After setting these option either you can restart OS X or run following in command line if you don't want to restart
. ~/.profile
For anyone that runs into this in the future, try restarting your computer and then running brew doctor again. That fixed it for me.

How to permanently change sudo's $PATH variable (Ubuntu 9.x)

I want add some directory to the $PATH when running sudo, this is a (semi) permanent requirement, not something that needs to be added to the scripts themselves. I notice that Django has managed to do it, (my $PATH when running sudo is "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/django/django-trunk/django/bin") - so how did it do that?
This is the line in the sudoers file that resets:
Defaults env_reset
You can work around this by adding PATH to env_keeps or by adding this line:
Defaults env_keep = "PATH"
EDIT: meder, you do not disable env_reset, you simply bypass the path reset
Or you can remove the offending env_reset line.
Even better though, you can declare a secure_path that will replace PATH when sudo is run:
Defaults secure_path="/bin:/usr/bin"
That way you can control what specific directories to include in the path.
I think this should work out if you save it in /root/.bashrc:
export PATH=/www/foo:$PATH
I forget if it's PATH or PYTHONPATH and if it actually matters, this is based on my user's .bashrc:
export PYTHONPATH=/www/django:$PYTHONPATH
You can set the variable in /etc/environment, and then use "sudo -i" to run the script (works in ubuntu 10.10).

Resources