duanshan1977 2017-07-28 22:22
浏览 227

在MacOS上添加路径时使用环境变量

I've found myself with the need to add a new path permanently in all terminal sessions on my Mac. Specifically I want to add the contents of my $GOPATH/bin to my $PATH.

So far I think my options are to either:

  1. Add it to my $HOME/.bash_profile file using export syntax.
  2. Create a file containing the path to add in the /etc/paths.d directory.

I've settled on option 2, because I like the idea of just adding files with one line in whenever I want a new path added permanently.

I have tried adding in a file /etc/profile.d/gopath containing ~/code/go/bin. This works. However, what I'd like to do is evaluate the environment variable, $GOPATH/bin such that if I decide to change my $GOPATH I only have to change the variable. However, that just adds the literal words "$GOPATH/bin" to my path, it doesn't actually add the directory to my path. The $GOPATH bash environment variable is currently set in my ~/.bashrc file.

Some questions:

  • Why doesn't the $ syntax evaluate in the $PATH or setting of $PATH? Is that not bash?
  • What comes first, the inclusion of ~/.bashrc, ~/.bash_profile or /etc/profile.d? It is reasonable of me to think that the environment variable would be there when setting the $PATH?
  • How can I have this environment variable be evaluated and substituted if it is feasible?

Thanks for your help. All my searches don't seem to come up with the above answers.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 求数学坐标画圆以及直线的算法
    • ¥35 平滑拟合曲线该如何生成
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了
    • ¥15 链式存储应该如何解决