add command to path in OSX Mavericks - macos

I'm trying to add a variable to my path in my OSX Mavericks using ~/.bash_profile, but when I type it, I get this error:
-bash: /Users/MyUser/.bash_profile: No such file or directory
I've read somewhere that in Mavericks it's done in a different way.
Anyone knows how to do this?

I am using ._bash_profile and .bashrc on Maverick, this work well.
If it does not exist, you can create and edit it using, vim, emacs or any editor.
$ touch ~/.bash_profile
$ open ~/.bash_profile -a "TextEdit"
This is my .bash_profile, the second line (export PATH) is what you are looking for.
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
See, it works ! Ahahah goo.gl/eDBVD0

Related

macOS Catalina 10.15(beta) - Why is ~/.bash_profile not sourced by my shell?

I want to set the environment variable I added below the line to ~/.bash_profile and ~/.profile but it didn't work.
export JBOSS_HOME=/Users/{USERNAME}/Desktop/jboss7
Afterward, exit the terminal and open it again when executing echo $JBOSS_HOME I get nothing.
Apple has changed the default shell to zsh. Therefore you have to rename your configuration files. .bashrc is now .zshrc and .bash_profile is now .zprofile.
If you for some reason (as me) don't want to rename/move your ~/.bash_profile file you can do the next things:
Create a new file ~/.zprofile
Type there source ~/.bash_profile
Save and close
Run a new terminal session
You can just copy your existing bash_profile and name it zprofile and it will work fine.
Run the below command in terminal and you are set after closing and opening new terminal.
cp ~/.bash_profile ~/.zprofile
I created a new file called
/usr/local/bin/mybash
which contains a wrapper script:
/usr/local/bin/bash --init-file $HOME/.bashrc
I installed this local/bin/bash from HomeBrew.
Full Sequence of Events
brew install bash
echo "/usr/local/bin/bash --init-file $HOME/.bashrc" > /usr/local/bin/mybash
chmod +x /usr/local/bin/mybash
Then I opened the settings for terminal.app [cmd-comma]. Under the General Tab, select the radio button for Command (complete path)
In the text box change the text from /bin/zsh/ to /usr/local/bin/bash.
After you close a Terminal window, variables you set in that window are no longer available. If you want the value of a variable to persist across sessions and in all Terminal windows, you must set it in a shell startup script. For information about modifying your zsh shell startup script to keep variables and other settings across multiple sessions, see the “Invocation” section of the zsh man page.
You can use ~/.zlogin to add your variables.
Check out this reference.
changing the bash profile to zsh profile works and source it as well to see in action.
vikas#Vikas-Kumar ~ % mv .bash_profile .zsh_profile
vikas#Vikas-Kumar ~ % source .zsh_profile
You can create a simbolic link and keep your .bash_profile file with this:
ln -s .bash_profile .zsh_profile
source .zsh_profile
Any changes in .bash_profile will be reflected in .zsh_profile
Even with os Catalina /bin/bash comes for free, brew is not needed. Simply create your .bash_profile and set shell in terminal settings to /bin/bash. it automatically finds your .bash_profile. z-shell is not bash-shell and simply renaming will work in most cases but definitely is not correct.
you don't need to update the file, zsh is mac's default, put this in terminal. e.g.:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
cp zprofile ~/.zprofile
Add to .zprofile:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
eg. by >vi .zprofile
Done

added wrong path to .bash_profile now I can not found any command

I was trying to add conda into my path. But after I added
export PATH="/data1/neyozhyang/anaconda3/bin/conda"
to my .bash_profile I can not use most of the commands like ls anymore.
It is a linux server.
echo $PATH gives me /data1/neyozhyang/anaconda3/bin/conda
while echo $HOME gives me /data1/neyozhyang
You can choose an editor by it's full path and open ~/.bash_profile.
$ /usr/bin/vim ~/.bash_profile
$ /usr/bin/nano ~/.bash_profile
$ /usr/bin/emacs ~/.bash_profile
And modify the PATH line:
export PATH="/data1/neyozhyang/anaconda3/bin/conda:$PATH"
This might help you get back on your feet (although you don't specify your OS)
PATH=$(/usr/bin/getconf PATH)
That gives you something like /usr/bin:/bin:/usr/sbin:/sbin so you should be able to access the base utilities.

-bash: vim: command not found

I have been trying to install something in my bash_profile, which looked like this:
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
I was trying to add the Path to my pg_config file: /Applications/Postgres.app/Contents/Versions/9.6/bin
So my bash_profile looked like:
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
When I tried to source the file i got:
-bash: /usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:: No such file or directory
When I try to open the bash_profile I now get:
-bash: vim: command not found
What have I done wrong?
Additional info
I have installed Python, PGAdmin4 and Django via Homebrew
I have downloaded Postgress.app also and was trying to install psycopg2, when it told me I had no pg_config. So I was trying to add the path to my bash_profile. Which I think is the right thing to do
#melpomene and #Jdamian I think were right here. I had trouble trying to then find and open my bash_profile as I couldn't use the terminal to run:
defaults write com.apple.finder AppleShowAllFiles YES
Thankfully this answer helped though: https://apple.stackexchange.com/a/186378/70982
I navigated in finder to my ~/ folder and and ran
⌘ CMD+⇧ SHIFT+.
Opened in sublime and My path had was written as this:
export PATH=/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:
$PATH
So I removed the carriage return so it all fits on one line and that seemed to help. I can now open Vim

Java_HOME not found when changed shell from Bash to Zsh on OSX?

This is weird, I have set JAVA_HOME for my mac which can be found when I am using bash shell, but if I change shell, I get a message saying JAVA_HOME not set. What could be going on here?
I stumbled upon your question when trying to solve the same issue while migrating from bash to oh-my-zsh. The reason it's not there is that there is no code setting it for zsh but there was for bash. Generally theres something exporting JAVA_HOME whenever a new bash window is opened so it's always set for you. There is a good thread where this might be happening on the Unix & Linux StackExchange site.
To do the same thing in zsh, you can edit the .zshrc which is run every time zsh starts. I found a sample .zshrc which got me most of the way. The key line being:
export JAVA_HOME=`/usr/libexec/java_home`
Here is the file which I appended to the end of my existing ~/.zshrc file:
#zshrc, interactive shell settings
export ZSH=$HOME/.zsh
# emacs integration
[[ $EMACS = t ]] && unsetopt zle
# env
if [[ -e /usr/libexec/java_home ]]; then
export JAVA_HOME=`/usr/libexec/java_home`
fi
if [[ -e /usr/local/lib/node_modules ]]; then
export NODE_PATH=/usr/local/lib/node_modules
fi
# path
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
export PATH=/opt/usr/sbin:/opt/sbin:/opt/usr/bin:/opt/bin:$PATH
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
export PATH=$HOME/.cabal/bin:$PATH
export PATH=$HOME/.gem/ruby/1.8/bin:$PATH
export PATH=$JAVA_HOME/bin:$PATH
export PATH=$HOME/.bin:$PATH
setopt null_glob
# source all files in zsh root
for include in $ZSH/*.zsh; do
source $include
done
# source all non-controlled files
for include in $ZSH/private/*.zsh; do
source $include
done
unsetopt null_glob
Then source ~/.zshrc to run in the current shell (or just start a new one) and you should be able to see that it is set with export | grep JAVA_HOME.
I also ended up running mkdir ~/.zsh to create the directory this is looking for and removing the .cabal and .gem lines as they were not needed for me.
I have just installed Mac OS Catalina Version 10.15 and found that environment variables such as JAVA_HOME and others that have been set in my .bash_profile :
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
export ANDROID_HOME=/Users/mynziak/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export M2_HOME=/usr/local/Cellar/maven/3.6.2/libexec
export M2=${M2_HOME}/bin
export PATH=${PATH}:${M2_HOME}/bin
are not set in fact!
I saw % in terminal instead of general $ that means you are using a zsh shell instead of bash shell. With Catalina zsh is now the default shell and bash will be completely gone in the future.
oh-my-zsh shell:
https://ohmyz.sh/
So you have to setup all environment variables in .zshrc file.
I just copy-pasted every variables from .bash_profile in to .zshrc and re-opened terminal.
Files .bash_profile and .zshrc are hidden (cmd+shift+. - show hidden files in finder) but can be found in path:
/Users/mynziak/.zshrc
but use own username!
When you set JAVA_HOME in a shell, then it is active and available only for that context, and it will be gone when you close that shell.
Instead either change global environment (or) your .bashrc to include it. So that every time you start a shell, the variable will be available.
edit the .profile or .bash_profile to include the JAVA_HOME.
export JAVA_HOME=`/usr/lib....`
and also below command will return the path for java home directory.
/usr/libexec/java_home -v 1.7
where 1.7 is the version you want.
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
export PATH=$JAVA_HOME/bin:$PATH
Add above 2 lines in ~/.bashrc or ~/.zshrc and reload the file using source command.

Generating ctags tags inside vim within OSX doesn't work

I'm using terminal vim in OSX and I've installed ctags via homebrew
then I have added the /usr/local/bin/ directory to my PATH
and also aliased CTAGS to use the homebrew installed version
all of this in my .zshrc, and It works fine.
The problem is that when I try to run :!ctags -R . within VIM
It fails because it doens't recognized the option '-R'
I have runned :!which ctags and returns
/usr/bin/ctags
instead the /usr/local/bin/ctags
is any way to solve this?
UPDATE
I add my zshrc file
# number of lines kept in history
export HISTSIZE=1000
# number of lines saved in the history after logout
export SAVEHIST=1000
# location of history
export HISTFILE=~/.zhistory
# append command to history file once executed
setopt inc_append_history
autoload -U compinit
compinit
# Colors
autoload -U colors
colors
setopt prompt_subst
# Save a smiley to a local variable if the last command exited with success.
local smiley="%(?,%{$fg[green]%}☺%{$reset_color%},%{$fg[red]%}☹%{$reset_color%})"
# Show the relative path on one line, then the smiley.
PROMPT='%{$fg[cyan]%}%~ ${smiley} %{$reset_color%}'
RPROMPT='%{$fg[cyan]%} $(~/Dotfiles/rbenv-version.sh)$(~/Dotfiles/git-cwd-info.sh)%{$reset_color%}'
# Example aliases
source ~/Dotfiles/zsh/aliases
source ~/Dotfiles/zsh/plugins/bundler.zsh
export SHELL=/bin/zsh
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
export PATH="$HOME/.rbenv/bin:$PATH"
export PATH=/usr/local/bin:$PATH
eval "$(rbenv init -)"
export LC_ALL=en_US.utf-8
export LANG="$LC_ALL"
export EDITOR=vim
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
I found out what was the problem, accordingly to this answer in superuser
Vim 'ignores' your aliases because your shell is not in a 'mood' to
parse your .bash_profile/.bashrc (you did not specify, where your
aliases are defined) because it is not started as a login/interactive
shell (read here to find out more about what is read when and for what
reason).
and the solution for me was to set a global path like described here
was to edit my /etc/paths
and add /usr/local/bin to the beginning of the file (in other case it doesn't work)
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

Resources