Will I lose my environment variables if I upgrade to macOS Catalina? - macos

I've heard that it's best to wait after a new OS comes out until a few updates come in so that the build is a bit more stable. However, I'm also wondering if I will have to set up my environment, PATH, etc again after upgrading. Will updating change anything or will everything be the same as before?
(I'm currently on macOS Mojave 10.14.6)

One thing to note is that environment variables can live in different places, so it may depend on which ones you're referring to.
Usually if Mac OS upgrades need to change a file that you're likely to customize, like the httpd.conf file, they'll make a backup first. But there's no guarantee; it's good to keep a Time Machine backup handy from before you upgrade. With that you can copy in anything that got lost.
Also note that Catalina is switching the default shell from bash to zsh, so if you have environment variables in .bash_profile or .bashrc, those will be ignored. You can switch back to bash if you want, or configure zsh with similar settings.

Starting with macOS Catalina -- by default it takes zsh and hence you need to change in zprofile. Please follow below steps
touch ~/.zprofile; (// This will create the profile)
open ~/.zprofile; (Open this in an editor)
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.11.jdk/Contents/Home
export GRADLE_HOME=/Users/myuser/Documents/installs/gradle-6.8.3
export PATH=$PATH:/Users/myuser/Documents/installs/gradle-6.8.3/bin
source ~/.zprofile (Execute the new .zprofile by either restarting the terminal window or using this)

Related

How to export everything useful in my iTerm to another system

I am currently using iTerm2 3.4.4 on my macbook pro. I am getting a different macbook and would be installing iterm on that one as well.
I want to export as much as possible from the older machine and import it into the new one. Some things I can think of it profile settings, command history, etc. How can I export these things and import them in the new machine ?
Is there an iTerm folder I can just copy and paste ?
You can export your profile by going to Settings - Profiles, then go to other actions and then Save Profile as JSON. You could copy the whole /Users/yourusername/Library/Application Support/iTerm2 folder to your new machine, which probably works as well. The command history depends on the shell that you're using, it has nothing to do with iTerm.
Bash History: ~/.bash_history
Zsh History: ~/.zsh_history
Fish History: ~/.local/share/fish/fish_history
The shell configurations depend on your shell as well.

Trouble opening Ncurses Examples in OS X

I recently downloaded ncurses from here and have compiled it using ./configure and make
As it is recommended in the README, I compiled the example programs that come bundled with the package. The programs compiled without any issue, but every time I run the programs I get the following errors:
Terminal type "xterm-256color"
terminals database is inaccessible
Changing the terminal's type using TERM=xterm and export TERM don't seem to solve this issue, and I'm just stuck. Will ncurses work if I included them in my C/C++ programs, or should I make sure the examples work?
Thanks in advance
Probably you did not install the terminal database, or did not tell the programs where to find it.
OSX comes with ncurses 5.7 (old, but not the problem here), with the terminal database in /usr/share/terminfo. However by default the configure script assumes you want to install in /usr/local. You can tell the programs where there's a terminal database by setting the TERMINFO environment variable, or (better), setting TERMINFO_DIRS to list both locations (with the newer one first of course).
For a start, something like
export TERMINFO=/usr/share/terminfo
should be enough to make the examples run.
Further reading:
TERMINFO
TERMINFO_DIRS

Setup default Ruby variables in RubyMine

I use mac and rubymine 7.1.2 and I want to setup default environment variables? Is it possible to setup them up per run configuration so every test, rails generator, rails console has access to them.
Is there something like .env file or something else, so it's possible just set them once?
Jetbrains actually has a page to help you do just this:
Mac OS X applies .bash_profile and .profile only for Terminal.app environment and Apple's technical documentation suggests using ~/.MacOSX/environment.plist for other applications. So, by default PATH value will differ for RubyMine and the console.
MacOS 10.6 or later
We recommend to manage your environment variables using free
Enviroment Variables preference pane instead of environment.plist
manual editing.
MacOS < 10.6
Unfortunately, the "environment.plist" approach doesn't always work on
MacOS < 10.6, e.g if you start RubyMine from Spotlight the environment
is not applied.
Thus real solution is to set your environment variables in
/etc/launchd.conf (thanks to David Goudreau for this tip). For
detailed description please read Mac OS X Global Environment Variables
article.
So you should:
Open /etc/launchd.conf file (e.g. $sudo nano /etc/launchd.conf)
Then set correct PATH env variable
setenv PATH /Users/romeo/.gem/ruby/1.8/bin:/opt/local/bin:/opt/local/sbin:/opt/local/libexec/git-core:/usr/local/mysql/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Set other env variables for RubyMine if necessary
Save changes
Reboot
P.S: If you always launch RubyMine using Dock or QuickSilver and do
not use Spotlight you can install Enviroment Variables preference pane
and use it instead of the manual environment.plist editing.
NB: Please don't miss "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
in the end of PATH value, because PATH=...:$PATH doesn't work here.

my terminal can't run on mac os 10.9?

I used to install something from github,I stoped it and I can't open iterm-2 too
and I open my Bash ,it appeared
Command not found: /usr/local/bin/bash
[Could not create a new process and open a pseudo-tty.]
I can't input any words.
What should I change?
Google is full of others asking for help with this problem and half-baked solutions, including reboots (re-login should do it if env changed), reinstall (why?) etc.
Looks like a clone of I messed up my terminal environment on Mac OS X and was wondering how to fix it judging by inability to start bash from /usr/local/bin. System default should be in /bin or /usr/bin.
Your terminal (console or iterm2) may have an option to specify shell explicitly, used that.

where is $PATH set in xcode?

It looks like xcode's $PATH environment setting is different from my user shell environment.
Where does xcode get the $PATH setting from and what's the best way to append to the search path?
if you're writing a Run Shell Script build phase, you can just do:
PATH=${PATH}:/opt/local/bin
or whatever inside the script content.
There's some confusion in these answers, as some of them are trying to solve the $PATH for the built executable being run by Xcode. But the question is about Xcode, implying that it's about the build process itself.
For example, in a Build Phase Run Script step that runs an executable installed by Homebrew. It's not a good idea to hard-code the build process to include a path that is specific to one build machine (New macOS versions come out, new developers join the team, etc.)
The problem has multiple layers:
Changing $PATH in bashrc/zshrc/profile takes effect on shell sessions, but not in macOS applications
To solve this, you can set the PATH for applications using:
sudo launchctl config user path $PATH
You will then need to restart your machine for the change to take effect. You will need to run this again if you change your $PATH.
(This came from a comment on GitHub.)
Xcode by default does not use the system $PATH, and replaces it with its own sanitized value
This is solved by changing a User Default. This probably has some risk, since Xcode does this sanitization to ensure that its own build tools are used, and if you have executables with the same name in other places, they might be run instead. Caveat emptor!
defaults write com.apple.dt.Xcode UseSanitizedBuildSystemEnvironment -bool NO
And it looks like this gets reset on every restart of macOS, so be prepared to issue this command every time you restart.
(This part came from this answer.)
The easiest solution is to add the PATH variable in Xcode.
PATH=${PATH}:/usr/local/bin
This applies for OSX 10.7 and earlier ONLY.
XCode gets its environment variables the same way as other OS X processes, from ~/.MacOSX/environment.plist.
Check developer.apple.com/qa/qa2001/qa1067.html for details on how to set things.
In Xcode 5 you can add your PATH as a variable to either a target or the project settings.
Add a custom variable with the +sign on the top of the page
Edit the name of the variable to be PATH and add your preferred value (e.g. /usr/local/bin for a default install of homebrew.
If you are talking specifically about the executable search path environment variable named PATH, then there are a few places that it is set:
In your shell settings if it is a command line tool. Depending on your shell, this could be ~/.cshrc, ~/.profile, ~/.bash_profile, etc.
In the environment.plist file that was mentioned earlier.
If you are in a debugger, then it is whatever gdb uses. I believe that gdb will read commands from ~/.gdbinit if it exists.
XCode lets you set environment variables within the Info page for executables.
This is an update for later versions of macOS and Xcode as things have altered. This is with Xcode 11.0 and macOS 10.14
The biggest issue is that ~/.MacOSX/environment.plist does not get read now.
Build Settings
This means that if in the build you need the PATH set, e.g. for external builds and they run executables there is no simple solution. /etc/paths does not seem to be read either.
The solution is as in #GhostLyrics answer to add the PATH variable in Build Settings. However as noted in comments Xcode will not just use that value but it puts its own values before that. Also it does a straight textual substitution and so you need to also add the separator that PATH uses i.e. the : (colon). The value I have added is :opt/local/bin I also found that you can only do this for a target and not at the project level.
Run Shell Script
This is the simple case as in this answer
PATH=${PATH}:/opt/local/bin
or whatever inside the script content.
Alternatively put this change in your non login shell starter file e.g. ~/.bashrc ~/.zshrc
Running the executable
This is done in the Schema in the Run portion.
Set PATH in the environment variables as stated in answers here. Note I have not tried this and I am not certain how much of the PATH needs setting.
Xcode doesn't look at your shell path environment.
Have a look at NSProcessInfo; and do an NSLog to see what comes up.
If you want a path to apply to all graphical programs you need to set up the ~/.MacOSX/environment.plist. as described.
The recommended way to set the environmen variables are actually in /etc/paths and etc/paths.d although these are also not picked up by Xcode.
I asked about this here.
Nothing was working for me in XCode 7.
You need to set the PATH variable in XCode schemes.
Found the solution at:
Where to set environment variables for app?
Try opening your xcode project from the terminal, this worked for me: open some.xcodeproj
Instead of opening xcode and then loading the project or double clicking on it.
I know... silly

Resources