Set environment variables on Mac OS X Sierra? - environment-variables

For example, I want to follow this guide on how to disable Brew analytics (under warning) but I have no idea how to find my environmental variables.
Most of the guides out there I found, such as this one, are all outdated; ~/.bash_profile doesn't exist according to how the answer described it. Can some please explain to a new MacOS user how all this now works?
Please note my understanding of Unix-based filesystems are limited. Treat me as a noob.

You can create ~/.bash_profile. The easiest way to create it is to use the touch utility: touch .bash_profile . It is common to have a .profile which is read if bash can not find .bash_profile. You can get the documentation from a terminal with man bash. You can edit either of these files with any text type editor (not word processor).

In case you're using zsh like me, you need to modify ~/.zshrc

I Android Gradle project root I do
gradle app:assembleDebug --stacktrace
but I get error
Minimum supported Gradle version is 5.4.1. Current version is 5.1.
and message says
/gradle/wrapper/gradle-wrapper.properties to gradle-5.4.1-all.zip
but it is
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
so why is Gradle not building?

Related

Where is the .bashrc file on Windows? (Daniel Kehoe's learn-rails tutorial book)

I previously asked a similar question with regards to cloud9, but I am now trying to do the same project in parallel on my windows 10 machine because I will not have internet access to use cloud9. I am trying to set up the configuration in preparation for following Daniel Kehoe's learn-rails tutorial book, but I am having trouble setting up the environment variables. The book seems to explain how to do it on Mac but I can not find the file in the atom editor. the book says to type the command:
atom ~/.bash_profile
However this just creates a new file that is not part of my rails app project directory. i have also tried
atom ~/.bashrc
which is the alternative but with the same result. It just creates a file unrelated to my project. The file is supposed to already exist somewhere.
I am supposed to put the environment variables into a file called ".bashrc" but I don't know where to find this file as it is hidden. How can I locate and open this file with Atom text editor?
.bashrc , .bash_profile are used in unix based operating systems for the terminal. In windows you set environment variables differently. In windows 10, search for environment variables in start menu, and select Edit the system environment variables and set them from there.
PS: You can have .bashrc if you have installed something like git bash, cygwin bash or bash for windows 10 or something else. And all 3 handle .bashrc differently.
Typing echo ~ in the Git Bash terminal will tell you where that folder is which contains the .bashrc file

PATH variable: how do I put mvim script "in a folder in my path"?

The version of vim on my computer is kind of old (6.2), so I installed MacVim (7.3). It comes with a shell script you can put somewhere to start MacVim from the terminal. The documentation says to "put this script in a folder in your path", and noob that I am, I'm trying to figure out what this means. I've searched and read, but I'm still lost as to what I need to do. Also, I'm running Tiger on a ppc mac, so Homebrew is unfortunately not an option.
Please help a noob!
The 'path' refers to a list of directories that are searched by the operating system to find executables. On the Mac, in the terminal, you can see this by typing:
echo $PATH
If you place that script in any of those directories, you should be able to run that script.

Setting Ros package path

I just began exploring ROS from the ros.org. I'm having some trouble setting the environment in Ubuntu. I get the following error while trying to set up a workspace automatically every time a new shell is launched.
bash: /opt/ros/fuerte/setup.bash: No such file or directory
bash: /opt/ros/fuerte/setup.bash: No such file or directory
Probably your ROS installation added this to your ~/.bashrc file and somehow the setup.bash file got (re)moved.
Try to locate that file and change the path accordingly. This should set the required enviroment variables in order to run ROS (core) etc.
Check answers.ros.org for ROS-related Q&A. The wiki is also a good source of information: www.ros.org/wiki.
First, open terminal and type the following command:
gedit .bashrc
Then press Ctrl + F and search fuerte. Delete everything about fuerte. Fuerte is old, download the new version groovy..
Check which version of ROS have you installed. There are newer versions of ROS like ROS groovy.
Probably you installed a new one, but follow the guide for the old ROS fuerte. First make sure which distro have you installed.

How to run multiple Groovy/Grails version

As I can run multiple versions of groovy / grails without having to change settings?
GVM (Groovy enVironment Manager) is a great option if you're on Mac, Linux, Solaris, or Windows with Cygwin. GVM supports the installation and management of Groovy, Grails, Griffon, and Gradle.
If Grails is your primary concern and you use a Windows PC in a locked down enterprise where Cygwin isn't an option, look at Gravy or write a batch file as noted above.
It's only about GROOVY_HOME/GRAILS_HOME and PATH environment variables. Start your Grails application from a bat file/shell script which sets these two variables, and you're fine.
Grails distinguishes settings stored in home/.grails for different versions, so versions won't clash there.
If you're on linux or osx, theres a shell script here which might help, and an alternative script is here
I am using 7 grails version on my ubuntu machine . put the code below at the bottom of .bashrc file.
function switchGrails() {
echo “Switching to grails version: $1″
sudo rm /opt/grails
sudo ln -s /opt/$1 /opt/grails
echo “Done!”
}
alias grails225=’switchGrails “grails-2.2.5″‘
alias grails224=’switchGrails “grails-2.2.4″‘
alias grails223=’switchGrails “grails-2.2.3″‘
alias grails233=’switchGrails “grails-2.3.3″‘
alias grails235=’switchGrails “grails-2.3.5″‘
alias grails237=’switchGrails “grails-2.3.7″‘
alias grails2311=’switchGrails “grails-2.3.11″‘
After save and exit . Compile the .bashrc file . Type cd and . .bashrc to compile .bashrc file.
For more reference : https://pkashyap28.wordpress.com/2014/09/11/manage-multiple-grails-application-in-ubuntu/
Add a tip if you are working on Windows: there's a way for quick-changing version of GRAILS. You just need to change GRAILS_HOME & GROOVY_HOME (by script, GUI,...) then CLOSE the cmd window used to run grais-app, then start it again. By this way, the change will be applied and you can avoid restarting.
Following the #tim_yates' answer. (unix based OS).
1- Put all grails versions under opt folder:
/opt/grails-2.3.1
/opt/grails-2.5.3
/opt/grails-3.1.1
2- Download and save grails.sh in somewhere you know. (I put mine at /opt/grails-selector)
Edit your ~/.bash_profile file. The PATH var should point to the folder you put your grails.sh. And set GRAILS_HOME to your default version (in case you are creating a new project, for example, it'll use this default version unless you declare to use another.
export PATH=$PATH:/opt/grails-selector
export GRAILS_HOME=/opt/grails-3.1.9
4- You're good to go. May you need to reopen your terminal or logout-login. When you call grails it will calls the grails.sh and then it looks for the version set in your project. So you it works automatically.

How do you manage developing with multiple versions of Grails using Windows?

We've been using Grails for a little while now and have been through a few Grails versions now. We don't always want to migrate our 'older' apps immediately but often use a newer version for new development. Changing the Windows environment variables is inconvenient since I sometimes have to work on two related projects at the same time that are running different versions of Grails.
In Linux, I'd probably create wrapper scripts or aliases to allow me to specify on the command line a version switch but I don't believe Grails supports this.
How are others that need to code against multiple versions of Grails managing it?
Update:
I created a gv.bat file to set the GRAILS\_HOME and PATH environment variables. I added a GRAILS\_INSTALLS environment variable (c:\usr\local\grails on my box) and removed the %GRAILS_HOME%\bin reference from my PATH.
gv.bat
#echo off
SET GRAILS_HOME=%GRAILS_INSTALLS%\grails-%1
SET PATH=%GRAILS_HOME%\bin;%PATH%
To do any Grails work I run > gv 1.1.2 or whatever version I need to work with. I'd like to figure out how to do a string replace in the PATH to change the value but that turned out to be difficult for me
I have a couple of bat files which changes the GRAILS_HOME and the system PATH according to which version I'm using.
It's not the most beautifull solution at all, but at least works for me.
I have a batch file, that looks like below.
#ECHO OFF
if "%1"=="231" goto grails231
if "%1"=="232" goto grails232
if "%1"=="233" goto grails233
if "%1"=="234" goto grails234
goto end
:grails231
set GRAILS_HOME=F:\softwares\grails-2.3.1
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:grails232
set GRAILS_HOME=F:\softwares\grails-2.3.2
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:grails233
set GRAILS_HOME=F:\softwares\grails-2.3.3
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:grails234
set GRAILS_HOME=F:\softwares\grails-2.3.4
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:end
It can be run like 'setgrails 233' and it will set the grails 2.3.3
IntelliJ allows you to specify which version of Grails to apply as a per-project facet configuration. The Eclipse plugin has yet to achieve this level of abstraction.
It's now MUCH much later, and GVM is not the tool it once was. Instead, I use SDKMAN (https://sdkman.io/) and, with Windows getting some linux-like tooling, or using Cygwin, etc. it's installable on Windows.
------ OLD answer below ------
GVM is a tool for unix/mac environments to manage Groovy/Gradle/Grails/more versions, and someone finally made a Windows equivalent called Posh-gvm (short for Power-shell GVM). It's very useful and easy to use to download and configure your environment for whichever version of these tools you want to use at any point in time.
If you're using an IDE, posh-gvm is still a great way to download/install the new versions as they come out, and your IDE can point into the posh-gvm install directories.
I have the same issue as you. For my concern, I have written a batch script (grails_version.bat) accessible from my Windows PATH home.
Set up your GRAILS_HOME to your standard Grails version and each time you want to run a Grails app into another version than the standard one, open a command prompt, run the batch script (>grails_version) and run your grails commands (ex: grails run-app).
If your are using IntelliJ, you can configure the grails version per application.
Here is the code:
#echo off
set v11=1.1
set v111=1.1.1
set v12M2=1.2-M2
set v12M3=1.2-M3
set v12M4=1.2-M4
set /p grails_version= What is the grails version (%v11%, %v111%, %v12M2%, %v12M3% (default), %v12M4%)?
if "%grails_version%" == "%v11%" goto :set_grails_home
if "%grails_version%" == "%v111%" goto :set_grails_home
if "%grails_version%" == "%v12M2%" goto :set_grails_home
if "%grails_version%" == "%v12M3%" goto :set_grails_home
if "%grails_version%" == "%v12M4%" goto :set_grails_home
if "%grails_version%" == "" goto :set_grails_home_default
:no_valid_input
echo The input version is not valid
exit
:set_grails_home_default
set grails_version=%v12M3%
:set_grails_home
set GRAILS_HOME=D:\Install\grails\grails-%grails_version%
path = %GRAILS_HOME%\bin;%PATH%
echo GRAILS_HOME=%GRAILS_HOME%
Enjoy.
I do that in Windows as below.
So I just change GRAILS_VER environment variable.
I can change my grails version anytime.
On Linux/Mac, GVM is a fantastic tool for installing and working with multiple versions of Grails, Groovy, etc. You can't use GVM itself on Windows1, but there is a clone posh-gvm that will run under Powershell on Windows.
AFAIK this is because Windows doesn't support symlinks
The thing I would change about these answers is the PATH handling. Each time you run the script and change versions, you will extend your path one more node. It works, but messy. Try creating a $path2 with no reference to your JAVA_HOME or GRAILS_HOME and the path become path2+grails+java. Example: set PATH="%PATH2%;F:\softwares\grails-2.3.1;path2java7.
The only reason I add the Java7 reference is that I need Java 6 for my older grails app and Java 7 for newer grails.
Check out this link, it explains exactly how to do that using cygwin and mapping several aliases.
Also, learn how the plugins directory work and replicate it several times for each version of Grails. I also use global plugins for the ones I use often, like tomcat, hibernate, dbUtil, console, etc.
Say you want to switch between 1.1 and 1.2M4 - you could have those directories setup with the plugins you are using:
c:\Users\username\.grails\1.2-M4\projects\projectname\plugins
c:\Users\username\.grails\1.1.1\projects\projectname\plugins
Then, take applications.groovy and make several copies, like
application.groovy.1.1
application.groovy.1.2M4
Now, to switch, you just need to rename the application.groovy.X to application.groovy and you are good to go (after running grails clean of course):
grails1.1 run-app
grails12M4 run-app
Lastly, there are other differences between versions (i.e. new 1.2 is introducing dependencies DSL), but most of the time things are backwards compatible enough that you can come up with a common denominator.
Some answers are outdated.
Seems that the best option nowadays is SDKMAN!:
SDKMAN! installs smoothly on Mac OSX, Linux, WLS, Cygwin, Solaris and FreeBSD. We also support Bash and ZSH shells.
Is also possible to install on Windows, but SDKMAN "can not be installed natively on Windows and requires WLS, Cygwin or MSYS+MinGW".
After that, you can choose the Grails SDK and which version you want. For example:
sdk install grails 1.3.7

Resources