"/bin" not in PATH - terminal

I know this is a commonly asked question however every solution I have tried to date has not fixed anything. Until about a week ago, my PATH variable was clearly defined (and is clearly defined still for normal bash sessions) and I always could open tmux and run things through intellij without fail. Now every session causes me to have to re associate my PATH with the command PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
. I have tried editing multiple bash files, made sure my /etc/environment and /etc/bash_completion both have the same exact PATH defined (same as the one above), along with an assortment of blog reading and googling. I also have updated both my .bashrc and .profile with an export of the path. Any help is greatly appreciated and thank you for your time helping me with the issue.

For anyone else having this issue, this is what was happening for me and how I fixed it.
My .bash_profile had been redirected due to a deprecated package system I at one point used to use. This caused my PATH to point at my java home. This was causing the system to not initialize properly on each launch, stopping the .bashrc defined PATH from loading properly. All I did to fix this was edit my .bash_profile to point at the default PATH value: export PATH = /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
That fixed all of the issues and now my tmux windows load and work properly

Related

Possibly corrupted ~.bash_profile [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 3 years ago.
I will try to outline this as best I can because I know other people have had a version of this problem.
I received a routine update to Conda last week, which asked me to change the path for my environments. New to development and not knowing better, I was able to eventually access my ~.bash_profile and find that multiple installs of Anaconda had written multiple sets of system instructions. Again, not knowing any better, I wiped my profile and replaced it with Anaconda’s preferred path route.
Amazingly, Conda is about the one thing that is now working. I can activate my environments and run most of my Python commands, but none of my normal Terminal commands are working. I have tried solutions posted here including vi ~/.bash_profile, nano and echoing the path, but even when I access my profile, I do not know how to restore a functional bash. I somehow deleted my system’s ability to recognize Terminal commands including mkdir, -g, which, and so on.
A few Terminal promps that pop up on initialization:
-bash: open: command not found
-bash: /anaconda3/etc/profile.d/conda.sh: Permission denied
Any help here would be appreciated. I thought to restore from a backup, but Time Machine will not let me overwrite system configurations and I cannot drag & drop my old bash (the function to reveal hidden dot files is also disabled after deleting my bash) A link or gist to a good boilerplate bash profile for me to use would be nice, if anyone knows of one.
If /etc/skel exists on your machine, you can copy those files to your home directory to reset the profile to the default.

Cant access my bash files

So I wanted to install MySQL on my MBP and I edited my bash_profile, added a path variable, however when I run echo $PATH from iTerm2 I get my path as:
Robs-MBP:~ Rob$ echo $PATH
/usr/local/mysql/bin
Ive tried a lot of commands and even used sudo and it just says command not found. My fear is that I have completely messed up, and now nothing works. Please help.
You've made a simple mistake: all you've done is reset the PATH env variable. To correctly do this, you should always add the existing PATH to the end of whatever you're adding. In you case:
PATH=/usr/local/mysql/bin:$PATH
To fix your problem from the terminal, you'll need to reset your PATH to somewhere with a text editor. I don't know where this is located on OSX, so you'll have to find it. After you know where your path should point, run:
$ export PATH=<YOUR_PATH_HERE>
Then edit your bashrc to include the original path as described above, and restart the terminal.
Alternatively, open .bashrc with a GUI text editor and make the change from there. Your PATH decleration should always end in :$PATH to include the PATH created by your system.

exectuable path pointing to the wrong location, how do I update

I recently updated a nodejs executable using npm and now the executable is pointing to the wrong location. when I run the which command in terminal it is pointing to the old non-existant location. How do I update the executable path or shortcut. I'm not a unix person so not sure where that is set.
I don't necessarily need to update the path for all my apps in the environment, just curious to know why that path for the old executable is still hanging around and pointing to the wrong location.
bash caches the paths to executables you've run. You can reset the cache with "hash -r" (or start a new bash session or terminal).
I don't think which ever returns something that doesn't exist. It shows you which version of the executable is being found, based on the search order in your $PATH environment variable.
This $PATH variable is set in your shell. Type $PATH in the terminal to see what your path variable is set to. (Probably something like /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin)
See this question for some instructions to change your shell path variable: Set environment variables on Mac OS X Lion
Can you give more specific examples of where this stuff is, and what files you are looking at, because I don't think your description makes sense (with regard to "pointing to the old non-existant location")?

Where is the default terminal $PATH located on Mac?

I have been looking throughout the system but I cannot find it. When I do echo $PATH I get the stuff I added, plus the default path. I do not have a .profile, and I do have a .bashrc, but the default path is not in there. I am looking for it just to know where it is located because all the tutorials explain that its in .profile... but what if you don't have one? Where is it located then? Anybody have any ideas?
If you do sudo man path_helper, it talks a bit about how it puts the path together. You might look in /etc/paths and /etc/paths.d. I did, and found what I was looking for.
Many system-wide settings including PATH are set in /etc/profile which is read in by bash at startup. On Mac OS X this file usually uses path_helper to set PATH. This utility in turn reads the information from other system configuration files under /etc (see path_helper manpage).
Note that even if you disable the reading of the initialization files by bash (e.g. with command-line options like --noprofile) it will still inherit the environment of the parent process.
If you start at /etc/profile, it should look something like this:
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
It's testing to see if the file exists and if so, executes it. If you execute it by hand, you'll get something like this:
PATH="/usr/bin:/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin"; export PATH;
I believe that's what you're looking for. So it comes from /etc/profile, which in turn calls an executable that sets the path.
As mentioned in the accepted answer, the $PATH is built by first looking into the content of the file /etc/paths, and then looking into every file in the folder /etc/paths.d. So, the $PATH in the pre-installed bash system installation contains every entry in these files, as well as in other shell types.
However, because in the latest Mac OS versions the default shell is zsh, I followed a couple of tutorials in which the writer avoided to change the $PATH for the bash shell, and simply added new entries to the $PATH by editing ~/.zshrc the following way:
export PATH=/path/available/only/for/zsh/shells:$PATH
The above command adds /path/available/only/for/zsh/shells to the $PATH, and the added path will only be available in zsh shells.
I hope this helps someone who, like me, had too many entries in the $PATH in zsh shells, and couldn't figure out where they were coming from!
The .profile file on Mac is located in your user folder: ~/Users/youruser/
However, the .profile file is hidden. You can press Command+shift+. (command, shift, dot) while on Finder to see them.
There's one important fact I only realized today while debugging a problem: the profile settings (.bash_profile etc.) are only read by login shells. They are not read by the processes that are used to launch your applications.
You launch your applications in diverse ways: click the icon in /Applications, or type the name in Spotlight search, or click an icon in the Dock ... In all those cases, the application itself (i.e the binary or shell script inside the application) is launched by launchd without any parent shell. Meaning that your profile is not run and that your custom settings (PATH, environment variables ...) will be ignored.
That can cause all sorts of trouble, for example if you setup you environment to use a specific version of Java: your application will not see that and use the "default" java, which will be the one with the highest version number.
In my case, the problem is that my application was crashing when run via the application launcher, but runs fine when run from a terminal window ... The reason was that I had a custom path that included some libraries required by the application, but that was not available when the application was run by the launcher.
The solution I used was to symlink the libraries needed into /usr/local/lib

How do you get your path in Octave (on Windows)?

I used addpath(pwd) to get my .m files working in my projects directory. When I close the window and start a new window, the path I just added is gone. But the files still run.
Is it in my path or not? How do I see the directories I have added to my path?
Also, . is the first entry I see from path. Does that mean I don't need to add any directories because it will always search the current directory first?
Thanks.
Basically, yes.
You can add a directory to the search path using addpath(), but as you know, it only exists for the current session and is reset when you restart Octave. If you want a path to survive between sessions, add it to your octaverc, a script file that gets run whenever a new session gets started. Example path to octaverc file is:
C:\Octave\3.2.4_gcc-4.4.0\share\octave\site\m\startup
Since . is in your path by default, Octave will search your current directory for any function files that it needs. Using addpath(pwd) is somewhat useless if you're just going to stay in the same directory. However, there are some cases where it'd be useful, if for example you have a directory that contains your functions, and another one that has the data that you're working on: you could start in the functions directory, do addpath(pwd), and then cd to the data directory while still being able to use your functions.
You can create batch file, which will start Octave with your directory path. Please see example below:
octave-3.6.4.exe -p "C:\MyOctaveDiretory"
-p means addpath()
addpath(pwd); savepath();
Done.
I think there is a bug in Octave (I use version 4.0.3 on Windows). When I create a new file in current path, this can't be called by Octave ("error: 'foo' undefined near line 1 column 1"). If I restart Octave, it works. This addpath(pwd) trick helps me a lot (before I unsuccessfully tried rehash() and cd elsewhere and back again).
If you had the same problem, the reason for the symptom might be:
Start Octave.
Create newfile.m.
Call newfile - fails since Octave did not register its existence.
addpath(pwd) - causes Octave to register it.
Close Octave
Start Octave - now pwd is gone from path, but newfile.m is registered at startup.
call newfile - works
I faced a similar problem in adding path where the path was added by using addpath command directly in Octave GUI (Command Window). The path added was being shown in console window but none of the functions worked.
The problem was solved by changing the path directory from Windows directory to some other direction where OS is not installed.

Resources