Setting GMT into $PATH?

Hi There,

Trying to set up a new MacBook Pro with GMT. If this question has been addressed already in the forum, please feel free to point me to it… I’ve searched but cannot find what I am looking for. Been using GMT a long time, but always have issues with set up as I can never remember what I did n years ago when I set up the previous machine. Presently working on a Windows machine through cygwin, so I haven’t had to set up a Mac in nearly 10 years (and yes, that old machine is still going, sort of…) Anyway, I digress…

Situation so far, I have downloaded installed and launched GMT 6.4 for the first time. I used the Application Bundles from the GitHub. Trying to get the GMT to be callable from other directories. I tried the commands below, but I am not sure what to do on (b)…

Note 1: If you want to use GMT outside of this terminal or in scripts, then follow these steps:
        a) export GMTHOME=/Applications/GMT-6.4.0.app/Contents/Resources
        b) prepend $GMTHOME/bin to your path
        c) export PROJ_LIB=$GMTHOME/share/proj
        d) export GS_LIB=$GMTHOME/share/ghostscript/Resource/Init
        e) export MAGICK_CONFIGURE_PATH=$GMTHOME/lib/GraphicsMagick/config

I did something (followed some instructions from somewhere on the web) and now when I go:

echo $PATH

I get:

/Applications/GMT-6.3.0.app/Contents/Resources:/usr/local/bin:/usr/bin:/bin:/usr/sbin

BUT when I try to do a GMT command in a different directory, I get:

> wainui:~ olas$ pscoast
> -bash: pscoast: command not found

So, what’s the ‘right’ way to get GMT to run from elsewhere?

Should I uninstall and install it using the home-brew route?

Any help appreciated.

Thanks,

-jose

Hi Jose, if you wish to continue to run GMT4-style commands (no leading “gmt”) then see the sidebar item called Migrating from an Earlier Version on how to handle the missing gmt command.

Also, if you installed 6.4 you will need to edit your init file (.bashrc, .bash_profile, .profile, .cshrc or whatever) to change that 6.3 to 6.4 in the PATH.

Hi Paul,

OK, yes, I get that. But I think I am still stuck on the

b) prepend $GMTHOME/bin to your path

part of the deal.

I did this:

olas@wainui ~ % GMTHOME=/Applications/GMT-6.4.0.app/Contents/Resources
olas@wainui ~ % echo $GMTHOME                                         
/Applications/GMT-6.4.0.app/Contents/Resources
olas@wainui ~ % export PATH=$PATH:$GMTHOME/bin
olas@wainui ~ % echo $PATH  /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/GMT-6.4.0.app/Contents/Resources/bin

So I see that the GMT is in the PATH. When I then go

gmt coast or
gmt or
gmt pscoast

I do indeed get the Information for that command.

However, if I quit the terminal and restart, the changes to the $PATH are lost…

what do I need to type to make it stick?

THANKS!

-Jose

Another note, that was all in the zsh shell.

I switched terminal to be bash

from some previous fiddling I have:

wainui:~ olas$ echo $PATH
/Applications/GMT-6.3.0.app/Contents/Resources:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

not sure what I did to get the GMT part in there without the /bin at the end!

See the list of init files I mentioned (.bashrc etc) and open in editor and make the changes in the file that mas the /Application/GMT-6.3.0.app entry (fix it so it ends with the bin dir). Then quit terminal and start it up again. Now the PATH will be updated.

OK, now I have edited the /.profile file and added the /bin so echo $PATH gives me:

/Applications/GMT-6.3.0.app/Contents/Resources/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

but still no joy on the gmt coast

wainui:~ olas$ gmt
-bash: gmt: command not found

hmmm… I know I’m doing something dumb…

I think bash needs .bash_profile and .bashrc. I have no .profile myself and running bash,

Paul: found my ‘duh!’.

I changed the ‘3’ to a ‘4’ and now it works. didn’t notice that it was on ‘3’. was a leftover from when I first tried a few days ago before you released 6.4. then I downloaded 6.4 and threw away 6.3, so yeah, that’s why…

As for the /.profile thing, I have no Idea, I saw it somewhere online, lost the link now.

but regardless, it worked.

Now to update my scripts! oof…

-jose

See …share/tolls/gmt5syntax which promises to accept a GMT4 script and write out a GMT6 script. Might save some typing if it works as advertised.

1 Like

OK, now referring to items c, d and e above…

I got it all working, calling GMT from anywhere, so that is good,

I then modified my ancient script to add the ‘GMT’ bit before each command (still working in classic for now).

Everything runs fine but the GMT psconvert fails because I never ran items c, d or e above. I can see the plot I am making just fine in the .ps file

As a test, I ran those commands (a, c, d and e) in the terminal window where I was working, and after that, my GMT script worked great, I got the .png I was looking for.

but, as I suspected, when I quit terminal and started up again, those configurations were lost.

also, now I cannot replicate that behavior, i.e. running commands a, c, d, and e before running my script does not lead to successfully running GMT psconvert

do I put them in the .profile file as part of the $PATH? if so, I’m just not sure how that looks.

Thanks again, almost there!

-jose

Just copy those 4 export statements to your .profile (leaving out the a) b) etc) of course). Then quit terminal and restart.

1 Like

This should not be necessary (automatically found). If it was then it would be missing the export of GDAL_DATA dir.

Thanks Paul.

It is now working

In order to assist anyone else searching through the forum for this type of info, here is what I did:

Computer:
MacBook Pro 2021 Model
macOS Monterey (12.4)

  1. Installed GMT 6.4 from application bundles, double clicked it from inside ‘Applications’ folder. It gives you the following notes/instructions:

"Note 1: If you want to use GMT outside of this terminal or in scripts, then follow these steps:
a) export GMTHOME=/Applications/GMT-6.4.0.app/Contents/Resources
b) prepend $GMTHOME/bin to your path
c) export PROJ_LIB=$GMTHOME/share/proj
d) export GS_LIB=$GMTHOME/share/ghostscript/Resource/Init
e) export MAGICK_CONFIGURE_PATH=$GMTHOME/lib/GraphicsMagick/config

Note 2: GMT may use Ghostscript, GraphicsMagick, FFmpeg, and GDAL executables; see
/Applications/GMT-6.4.0.app/Contents/Resources/share/Licenses for details."

To accomplish the above:

  1. change the default shell to bash in the Terminal preferences (original default is zsh)
  2. do: nano /.profile to edit the startup profile
  3. type the following into the the .profile file:

export GMTHOME=/Applications/GMT-6.4.0.app/Contents/Resources
export PROJ_LIB=$GMTHOME/share/proj
export GS_LIB=$GMTHOME/share/ghostscript/Resource/Init
export MAGICK_CONFIGURE_PATH=$GMTHOME/lib/GraphicsMagick/config
export PATH=$GMTHOME/bin:/opt/homebrew/bin:/opt/homebrew/sbin:$PATH

  1. save it
  2. close open terminal windows and quit terminal
  3. restart terminal, type in ‘GMT’ at the prompt and you should get all the GMT info in the terminal window

Then I:
8) got one of my old scripts and appended ‘GMT’ before every classic module command
9) ran it and it worked.

Hope this is helpful for someone.

All the best,

-jose

You don’t have to change your default shell. The same steps work for zsh, except that ~/.zshrc is the file you need to modify.

1 Like