No .bash_profile on my Mac - eclipse

I'm trying to develop using Eclipse/Maven on my Mac and while setting environment variables there is no .bash_profile. I do ls -a and still not there. I see a .bash_history and .bash_sessions. Where am I supposed to set my JAVA_HOME and PATH?
Thank you!

In your terminal:
touch ~/.bash_profile; open ~/.bash_profile
Then make your edits and save. This is generic so make sure your path is correct in the above example.

For anyone else stumbling up on this after Mac Catalina,
Starting CATALINA the default shell is zsh.
The profile file name for zsh is ~/.zprofile.
To setup bash as your default:
Open terminal
Goto preferences and choose "Shell opens with"
Click on "Command(complete path)" and type "/bin/bash" to start bash shell

On terminal, enter this command: chsh -s /bin/bash
This will change shell for the current user to bash.
After that, you can see .bash_profile on the root folder.

Related

"Unable to resolve your shell environment"

On macOS Big Sur, I installed MacPorts and installed bash using it. I set my default shell to the MacPorts version of bash /opt/local/bin/bash by using chsh.
All was well.
I decided I would rather use Homebrew. I uninstalled MacPorts, installed Homebrew, installed bash via homebrew, and set my default shell to /opt/homebrew/bin/bash via chsh.
All was well, except when I am first starting vscode (from Finder) which reports:
Unable to resolve your shell environment: A system error occurred (spawn /opt/local/bin/bash ENOENT)
This is a totally reasonable complaint, since that binary no longer exists. It makes this complaint when launched from Finder, but not when launched from the terminal. There is no reference to this prior version of bash in my user settings.json file, nor is it in my .bashrc.
Where the heck could vscode be getting this path to bash from?!
Edit (2021-10-11): there is something strange going on here. If I open an integrated terminal in vscode:
$ echo $SHELL
/opt/local/bin/bash
$ ls -lh $SHELL
ls: /opt/local/bin/bash: No such file or directory
$ ps -p $$
PID TTY TIME CMD
45388 ttys001 0:00.12 /bin/bash -l
(there are no such problems in the regular macOS Terminal app)
Edit again (2021-10-12):
I tried resetting vscode (via rm -rf ~/Library/Application\ Support/Code).
I tried resetting vscode's cache (via rm -rf ~/Library/Caches/com.microsoft.*),
I downloaded iTerm2 and ran it; it loaded the correct shell (/opt/homebrew/bin/bash) without issue (tried this in hopes of determining if there was some other setting in macOS pointing at the old macports version of bash).
Had the same issue and was able to resolve this by changing the shell for the logged in user (using chsh -s, cf. the hint at the bottom of https://github.com/microsoft/vscode/issues/139867). As this change is not being picked up by VSCode in your currently logged in session, don't forget to explicitly log out and log back in again after performing this step.

Flutter path is not saving permanently on z shell mac os catalina every time after closing the terminal

i am using mac os catalina and i created .zshrc file and added the following line for flutter
export PATH="$PATH:/Users/me/development/flutter/bin"
this is the content of the .zshrc file:
but when i closed the terminal and reopen a new terminal, flutter command is not working. so every-time again and again, i need to type source $HOME/. to make it working.
is there any permanent solution so that the path will not be removed.
You mention that you got a MacBook that you then updated to Catalina after the fact. The default terminal shell for Catalina is zsh, but before Catalina it was bash, and any Mac that was updated to Catalina from an older version still has bash as the default. If this is the case for you, you need to do one of the following:
Change the default shell for your terminal to zsh with the command chsh -s /bin/zsh (more info)
Add the path export script to a file named .bash_profile instead (same location where you created .zshrc).
In my case adding the following to Users/me/.zshrc solved the problem:
export PATH="$PATH:/Users/me/development/flutter/bin"
Writing your export to PATH code in the .zshrc file is the answer with Mac Big Sur but also, don't forget to execute it before quitting your shell.
. ~/.zshrc
Open terminal.
vim $HOME/.zshrc
open another terminal
drag drop bind file inside flutter file to second terminal
on first terminal where vim is openned add this code
export PATH=(copy and past on second termainal path here)
Press "Esc" then write :wq! in terminal and press enter to exit vim.
close terminal test,open again test with command "which flutter"

Why working permanent alias in hyper terminal doesn't work in vs-code bash terminal?

I'm on Windows 10 machine and I just installed VS-Code to use instead of Atom. I tried to use permanent alias in VS-Code Bash Terminal which I had created & was working fine in Hyper Terminal, but it doesn't work in VS-Code terminal. Why is that & How can I fix it ?
I have
alias mongod="/c/Program\ files/MongoDB/Server/4.0/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/Server/4.0/bin/mongo.exe"
in my '.bash_profile' file
In VS-Code terminal, try and check your alias is still defined:
alias mongod
cd ~
more .bash_profile
You will then see if said alias is still there in that VSCode environment.
If it is: do a source ~/.bash_profile, and the alias should be operational.
see also "Why ~/.bash_profile is not getting sourced when opening a terminal?"
~/.bash_profile is only sourced by bash when started in interactive login mode.
When you open a terminal, the terminal starts bash in (non-login) interactive mode, which means it will source ~/.bashrc.
So in your case, move those alias definitions to ~/.bashrc.

How to add mongo commands to PATH on Mac OSX

I'm using MongoDb 2.6.1 following the material from https://university.mongodb.com/ (great material by the way) but I am not being able to add to my path the mongo commands.
I've followed this guide http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/ and I modified my .bashrc like this
export PATH=/Users/jonathancaballero/bin/mongodb/mongodb_2.6.1/bin:$PATH
And there is indeed where the binaries are (checked using the finder directly)
So my question is why I am not able to use mongod from any location in my terminal?
Please put the PATH export into .bash_profile:
export PATH=/path/to/your/mongo/bin:$PATH
Edit: The reason to put it into .bash_profile is that this file will usually get executed when bash is started as a login shell while .bashrc usually is exectuted for interactive non-login-shells. What usually happens is that .bashrc gets sourced in .bash_profile. This does not seem to be the case here. On MacOS X when you start a Terminal, .bashrc does not get executed. God knows why, as the shell opened should be an interactive non-login shell and therefor should execute .bashrc.
Another, albeit more "intrusive" solution would be to add the following to .bash_profile.
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
For those who are interested in the details: take a look into the according sections of bash's manpage

Set the default directory in mac terminal

I only use terminal (mac) for git, and I only use git for one directory. Is it possible to set the default directory (the directory when terminal is opened) to the directory where I use git, and if so how?
As of Mac OS X Lion 10.7, Terminal supports Resume and by default will automatically restore terminals you had open when you quit, restoring their working directories. So, you can just open a new terminal and cd to your git directory, then leave the window open when you Quit. Each time you reopen Terminal, the terminal will be there, in the same directory. (This works for bash by default. If you're using some other shell, you'll need to adapt the code in /etc/bashrc to your shell. I've posted code for zsh in my answer to Resume Zsh-Terminal (OS X Lion) on SuperUser.)
You can also arrange for Terminal to start a shell in a particular directory. You can customize or create a "Settings Profile" to issue a "cd" command when it starts:
Terminal > Preferences > Settings > [profile] > Shell > Startup > Run command
Enable "Run command" and "Run inside shell", then set the command to cd your_git_directory. When you open a new terminal with that profile, it will go to your git directory.
I recommend you Duplicate the current default profile (if you've never changed it, the default is "Basic") using the Action ("gear") menu at the bottom of the profiles list, then customize that profile.
Finally, to have it automatically open a terminal with this profile when you open Terminal, set
Terminal > Preferences > Startup > On Startup, open
to your custom profile. (On Lion, Resume will restore windows that were open when you quit, rather than perform the startup action. As I mentioned, you can just leave this terminal open when you Quit and it will be restored when you open Terminal again. Or, you can press the Option modifier key when quitting; the Quit menu item will change to "Quit and Discard Windows" and the next time you open Terminal it will perform the startup action.)
I like to have 'New windows open with: Same Working Directory'. All answers I've found for this question (many SO's) will break that setting by always going to the new home directory. Below is what I use at the top of my .profile (or .bashrc, etc).
export START="/Users/michael/my/starting/directory"
if [[ $PWD == $HOME ]]; then
cd $START
fi
This will see if you are in your HOME directory only on launch, and if so change to your new START directory. That way new windows won't automatically run this command.
The only caveat is if you're in your actual HOME directory and open a new window, it will take you to START. Which is expected.
Try echo "cd $directory" >> ~/.bash_profile
If you are using for example ZSH,
just add to your config file .zshrc this string:
# Working directory
cd ~/Desktop
or for instance:
# Working directory
cd $HOME/Desktop
Change path with your preference.
It just will return command to ZSH, you won't see it in terminal and it will start with your chosen path.
Use a Window Group. Arrange your shell window(s) as you'd want them to be on startup - cd to the directory you want in each, set colors, Shell--Edit Title, etc. Then go to Window--"Save Windows as Group...". Give it a name, check "Use window group when Terminal starts". Next time you start, this arrangement will be your starting point.
I modified #Michael Ozeryansky's answer to solve the caveat he mentioned:
The only caveat is if you're in your actual HOME directory and open a new window, it will take you to START. Which is expected.
To make your second terminal window tab starts from the Home or Any other dir:
export START="/Users/michael/my/starting/directory"
export DIR = "path/to/directory"
if [[ $PWD == $HOME ]]; then
cd $START
else
cd $HOME // or any other dir: cd $DIR
fi
If you modify the .zshrc file, the “New Terminal in Folder” Service shortcut will not work on Mac. I do not recommend.
On the iTerm2 terminal, I do the following:
Profiles --> Open Profiles --> Click the Edit Profiles button
Go to the Profiles tab --> General
Update the Working Directory