Did I mess up my PATH? .bash_profile - bash

I am trying to open up files from my terminal using atom. Which resulted in -bash: atom: command not found. I then followed, installing the shell commands from the editor. That resulted in "EEXIST: file already exists, mkdir '/usr/local/bin'" . I've previously tried to follow other recommendations on how to add the subl alias and I guess I tried way too many things, that I didn't understand. Could I have messed up my $PATH ?
When I echo my path this is what it is /bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin.
My bash_profile looks like this when I opened it with nano:
export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH
export EDITOR='subl -w'
I don't remember if I added that first line when I tried adding subl.
Should I remove that? I'm also using a MacOS High Sierra.
UPDATE
I removed what I had previously added in my .bash_profile and my path is now: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin.
I then ran the command: sudo ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom but got a ln: /usr/local/bin/atom: No such file or directory error

You can remove the export PATH statement from your .bash_profile; it doesn't add anything that isn't already there. (Except maybe /usr/local/sbin, but I would remove that until you can demonstrate a need for it.)
Initially, PATH will include the directories listed in /etc/path:
% cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Any of your shell configuration files can add to the PATH. Assuming you haven't significantly altered your configuration, /etc/profile will run path_helper to add any directories listed in files under /etc/paths.d.
You only need to update PATH if you need to add a directory that is not already there. If atom is located in one of the above paths, you don't need to do anything. It sounds like you attempted to create /usr/local/bin when it already (as it should) exists, then perhaps did not ultimately create the symlink for atom under /usr/local/bin.
Try running just the ln command from the question you linked (using sudo if necessary), then confirm that /usr/local/bin/atom does indeed exist.

Related

Error trying to make symlink to subl - can't find directory

I am trying to create a symlink to subl, but I am having issues. The instructions read: "Assuming you've placed Sublime Text in the Applications folder, and that you have a ~/bin directory in your path, you can run:"
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Initially, I got /Users/User/bin/subl: No such file or directory.
So I tried making the directory with mkdir /usr/local/bin and running a modified version of the above command:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
That worked, but when I ran subl --help this error popped up:
-bash: subl: command not found
I also tried mkdir ~/bin. No luck. I'm also concerned because the instructions say Sublime should be in the applications folder, which it is in Finder, but not under tbecks/Applications. Thank you for any help!
The first ln command you ran used /Applications/Sublime Text.app, but the second used Sublime Text 2.app. Since you tagged the question sublimetext3, I'm assuming that's the version you're using. Here's what you need to do to get the symlink working. First, verify subl is in the correct spot:
ls -l /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl
If you installed Sublime in the correct spot, something like this will print:
-rwxr-xr-x# 1 mattdmo admin 158192 May 11 21:47 /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl
Now that we know where the original subl is, we can fix the mistake you made using the ST2 path:
rm /usr/local/bin/subl
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
Next, we'll see if /usr/local/bin is in your PATH variable:
# reload bash's hashmap of executables
hash -r
# find subl, hopefully
which subl
If /usr/local/bin is in your PATH, the which command will print
/usr/local/bin/subl
If it does, you're good to go. If it doesn't, we'll need to add it to your path. Unlike another answer says, you should never mess around with anything in /etc unless you know exactly what you're doing. Instead, we'll make the change in your personal bash startup file. Depending on which version of OS X you're on, this file could vary. Go to your home directory by typing
cd
then run
ls -al
to show all of the files and directories, even the "hidden" ones that start with a dot/full stop .. You are looking for .bashrc or .profile. If both exist, or if neither exist, use .profile. Run
/usr/local/bin/subl ~/.profile
# or .bashrc
and add the following line at the bottom:
export PATH=$PATH:/usr/local/bin
Save the file and close it. Now, you can restart Terminal and your subl command should be ready to use! If for some reason it still doesn't work, try adding the above line to the other file (i.e., if you just added it to .profile, try adding it to .bashrc and vice versa).
when I ran "subl --help" this error popped up: "-bash: subl: command
not found"
Most likely /usr/local/bin is not in your path.
Add
PATH=$PATH:/usr/local/bin
at the end of your bash configuration file( most likely /etc/bash.bashrc) and then execute the command again or confirm the command is reachable using:
which subl
Edit:
Even better modify the PATH in ~/.bashrc if you wish to restrict subl only for you.

Unable to install modman, .profile is missing

https://github.com/colinmollenhour/modman/blob/master/README.md
I am trying to install modman.
First I install via:
bash < <(curl -s -L https://raw.github.com/colinmollenhour/modman/master/modman-installer)
modman is created at User/Username/bin/modman
I got lost on the next part:
source ~/.profile
I don't have .profile in my directory, so i created one in my user root and I added
export PATH=$PATH:/Users/Username/bin/modman
I am not sure if that is correct, when I cd to my project directory and
do modman init it returns modman: command not found
Why am I getting this message?
You add directories to PATH, not individual binaries.
export PATH=$PATH:/Users/Username/bin
Note the line from the installer that would have updated .profile for you:
echo -e '\nPATH="$HOME/bin:$PATH"' >> $HOME/.profile
(Typically, you might add $HOME/bin to the beginning of the path so that you can override system binaries, but in your case, it doesn't matter since you don't have modman installed outside your home directory.)

Cannot get subl command working for ST3 on OSX

I am trying to get the Subl command working on my Mac OSX Mavericks. I have ST3 in my root applications folder.
When I run the line below, I also run it with sudo and get the same message.
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
In the terminal I get the following error
ln: /Users/username/bin/subl: No such file or directory
I double checked to see if it was working or not with
subl --help
but get the following error
-bash: subl: command not found
I am trying to get this to work so I can use it with Git and open file with sublime from there https://help.github.com/articles/associating-text-editors-with-git#using-sublime-text-as-your-editor
My .bash_profile looks like the following
export PATH=/usr/local/git/bin:$PATH
export PATH="/usr/local/bin:$PATH"
export EDITOR='subl -w'
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
fi
Can anyone advise how to fix this problem,
Thanks
Most likely the issue is that you don't have a /Users/username/bin directory in the first place, so your ln command trying to create a symlink isn't working. Secondary to that, even if ~/bin did exist, it's not part of your PATH, so the subl command won't ever be found.
To make things much easier for you, just create the symlink in /usr/local/bin. It (hopefully) already exists, and is already in your PATH. Just run
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
and you should be all set.
In response to your comment: There are 2 commands here - ln, which creates a symlink, and export, which just creates an environment variable (PATH is a special environment variable that contains the list of directories searched for commands when you enter something in Terminal).
When you create a symlink, the entire directory tree needs to exist before the link will be created. So, while /Users and /Users/username already existed, /Users/username/bin did not, so the ln command failed, regardless of whether sudo was used. In order to create the bin directory in your home directory (also known as ~), you would first have needed to run mkdir ~/bin, then create the symlink with your first ln command (the one without the sudo). Next, you would have needed to add ~/bin to your PATH environment variable by replacing the first two lines in ~/.bash_profile with
export PATH=~/bin:/usr/local/bin:/usr/local/git/bin:$PATH
However, since /usr/local/bin was already in your PATH, the easiest solution was to create the symlink to subl there, instead of creating a new ~/bin directory, making the symlink, editing ~/.bash_profile, then restarting your shell.
I also have this requirement. I use alias instead of those symbolic link method. It is rather easy and here is how.
Step1: Open ~/.bash_profile, add below line into it then save and close it.
alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'
Step2: execute source to make the alias setting take effect.
source ~/.bash_profile
Now you can use command subl following by a file or directory path to open them, enjoy!

How to remove entry from $PATH on mac

I was trying to install Sencha Touch SDK tools 2.0.0 but could not run it properly. It created an entry in the $PATH variable.
Later I deleted the sencha sdk tools folder but didn't realize that the path variable is still there.
When i did echo $PATH I got -
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I searched on how to remove variables from $PATH and followed these steps :
Gave the command PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
Did echo $PATH which showed /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
gave the command export PATH
Closed terminal and reopened it. Gave the command echo $PATH. This time I got
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Can anyone tell me what am i doing wrong?
echo $PATH and copy it's value
export PATH=""
export PATH="/path/you/want/to/keep"
Check the following files:
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
Some of these files may not exist, but they're the most likely ones to contain $PATH definitions.
On MAC OS X Leopard and higher
cd /etc/paths.d
There may be a text file in the above directory that contains the path you are trying to remove.
vim textfile //check and see what is in it when you are done looking type :q
//:q just quits, no saves
If its the one you want to remove do this
rm textfile //remove it, delete it
Here is a link to a site that has more info on it, even though it illustrates 'adding' the path. However, you may gain some insight.
What you're doing is valid for the current session (limited to the terminal that you're working in). You need to persist those changes. Consider adding commands in steps 1-3 above to your ${HOME}/.bashrc.
If you're removing the path for Python 3 specifically, I found it in ~/.zprofile and ~/.zshrc.
$PATH contains data that is referenced from actual files. Ergo, you should find the file containing the reference you want to delete, and then delete said reference.
Here is a good list to run through progressively [copied from #Ansgar's answer with minor updates].
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
/etc/paths
/etc/paths.d/
Note that /etc/paths.d/ is a directory that contains files with path references. For example, inside this directory may be a file called, say, fancy-app, and inside this file you'll see an entry like below:
/path/to/fancy-app
This path will appear in your $PATH and you can delete the entry in the file to remove it, or you can delete the file if it has only the one reference you want to remove.
Use sudo pico /etc/paths inside the terminal window and change the entries to the one you want to remove, then open a new terminal session.
when you login, or start a bash shell, environment variables are loaded/configured according to .bashrc, or .bash_profile. Whatever export you are doing, it's valid only for current session. so export PATH=/Applications/SenchaSDKTools-2.0.0-beta3:$PATH this command is getting executed each time you are opening a shell, you can override it, but again that's for the current session only. edit the .bashrc file to suite your need. If it's saying permission denied, perhaps the file is write-protected, a link to some other file (many organisations keep a master .bashrc file and gives each user a link of it to their home dir, you can copy the file instead of link and the start adding content to it)
Close the terminal(End the current session). Open it again.
If the manual export $PATH method does not seem to be working after you close the terminal and open again, definitely check the shell configuration files.
I found a small script that kept adding some more path in front of the $PATH everytime it was open.
For zsh you can check the ~/.zshrc file.

reloading .profile on FreeBSD causes error

I have installed Google's Go language on FreeBSD 8.1, added the path to the compiler/interpreter to my PATH in .profile and now am trying to reload it.
$ . ~/.profile
And here is what i get:
/usr/local/bin/.: Permission denied.
I also tried to use source instead of ., but that gives an error per line of the file, like HOME=/root: Command not found.
What can I do about it? And is this the right place to ask such questions?
I believe that the right way to extend the user's path is to edit user's shell configuration file. The default shell in FreeBSD for regular users is tcsh, for which you can use the ~/.cshrc configuration file.
To modify the PATH environment variable, create or edit .cshrc file in your home directory and put there the following example line:
set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin)
Then run:
$ source ~/.cshrc
verify your setting with:
$ echo $path
/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /home/danger/bin
The default interactive shell on FreeBSD is tcsh. Its syntax is different from that of sh. It is only the latter that uses ~/.profile.
The right way to extend the path is to modify it in the default profile in /etc/login.conf. Then run cap_mkdb /etc/login.conf as root, log out and log in again.

Resources