macos MacPorts 如何安装软件包?如何激活通过 MacPorts 完成的 Ruby 安装?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1333569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does MacPorts install packages? How can I activate a Ruby installation done via MacPorts?
提问by Julian Weimer
After trying to install ruby19 on my machine (PPC, Mac OSX 10.5.7) using the following commandline
尝试使用以下命令行在我的机器(PPC、Mac OSX 10.5.7)上安装 ruby19 后
sudo port install ruby19
the version of ruby didn't change
ruby 的版本没有改变
ruby -v => ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
I assume that i have two versions of it installed on my mac, but how do i use the latest one now?
我假设我的 mac 上安装了它的两个版本,但我现在如何使用最新的一个?
回答by mipadi
By default, the Ruby 1.9 port in MacPorts installs the Ruby binary in /opt/local/bin/ruby1.9
. It appends a 1.9
to avoid stomping on Ruby 1.8.7 libraries and gems, since not all gems are compatible with 1.9 yet. So you have to launch Ruby 1.9 with ruby1.9
(and irb1.9
, etc.)
默认情况下,MacPorts 中的 Ruby 1.9 端口会在/opt/local/bin/ruby1.9
. 它附加 a1.9
以避免踩踏 Ruby 1.8.7 库和 gem,因为并非所有 gem 都与 1.9 兼容。因此,您必须使用ruby1.9
(和irb1.9
等)启动 Ruby 1.9
If you don't want to have to do this, you have two options:
如果您不想这样做,您有两个选择:
- Alias
ruby
toruby1.9
in your shell config file. - Install the Ruby 1.9 port with the
+nosuffix
variant. Be warned, however, that if you have installed Ruby 1.8 via MacPorts, installing Ruby 1.9 via MacPorts without the1.9
suffix may cause conflicts (with gems, etc.).
- 别名
ruby
toruby1.9
在您的 shell 配置文件中。 - 安装带有
+nosuffix
变体的 Ruby 1.9 端口。但是请注意,如果您已经通过 MacPorts 安装了 Ruby 1.8,那么通过没有1.9
后缀的MacPorts 安装 Ruby 1.9可能会导致冲突(与 gems 等)。
回答by Simon Groenewolt
To use a specific ruby version if you have two versions installed you can either specify an absolute path to the one you want. E.g. /your/path/to/ruby Or you can change your PATH setting in your .profile
如果您安装了两个版本,要使用特定的 ruby 版本,您可以指定一个到您想要的绝对路径。例如 /your/path/to/ruby 或者您可以在 .profile 中更改 PATH 设置
you can type
你可以输入
which ruby
to see the path to the ruby executable that is used at the moment.
查看当前使用的 ruby 可执行文件的路径。
using
使用
echo $PATH
You can see the current PATH setting. You have to prepend the path to your new ruby binary to the PATH so that it will be found before the other one.
您可以看到当前的 PATH 设置。您必须将新 ruby 二进制文件的路径添加到 PATH 中,以便在另一个路径之前找到它。
As ayaz already mentions, the default location of your macports stuff is in /opt/local. If you add /opt/local/bin in front of your path it should be fine. (Make sure to start a new terminal window after the change - they will not be picked up in your current session unless you explicitely 'source' the .profile file again)
正如 ayaz 已经提到的,你的 macports 东西的默认位置在 /opt/local 中。如果您在路径前添加 /opt/local/bin 应该没问题。(确保在更改后启动一个新的终端窗口 - 除非您再次明确“源”.profile 文件,否则它们不会在您当前的会话中被选取)
One note of caution: after prepending /opt/local/bin to your path the shell will alwaysprefer binaries in there to binaries found later, this can be an issue if you depend on specific versions in /bin, /sbin or /usr/sbin -- depending on your situation this means that you should not do it (if your computer is processing sensitive data and/or in a bank or something) or just have to remember that it could be an issue (if your computer is a normal development machine).
一个注意事项:在你的路径前面加上 /opt/local/bin 之后,shell总是更喜欢那里的二进制文件而不是以后找到的二进制文件,如果你依赖 /bin、/sbin 或 /usr/ 中的特定版本,这可能是一个问题sbin - 根据您的情况,这意味着您不应该这样做(如果您的计算机正在处理敏感数据和/或在银行或其他地方)或者只需要记住这可能是一个问题(如果您的计算机是正常的开发机)。
See http://www.tech-recipes.com/rx/2621/os_x_change_path_environment_variable/if you need some more hints on how to set your PATH on osx.
如果您需要有关如何在 osx 上设置 PATH 的更多提示,请参阅http://www.tech-recipes.com/rx/2621/os_x_change_path_environment_variable/。
回答by Telemachus
Just a quick clarification about MacPorts. Ayaz is right that, by default, MacPorts will install things in /opt/local. (This makes it easy to globally uninstall later, if you want, and it keeps MacPorts packages out of the way of OS X packages.)
只是对MacPorts的快速说明。Ayaz 是对的,默认情况下,MacPorts 会在/opt/local 中安装东西。(如果您愿意,这使得以后可以轻松全局卸载,并且它使 MacPorts 包不受 OS X 包的影响。)
When you install MacPorts, it will normally edit your $PATH
(and your $MANPATH
) for you by updating your user's .profile(creating it, if it doesn't already exist).
当您安装 MacPorts 时,它通常会通过更新您用户的.profile(创建它,如果尚不存在)来为您编辑您的$PATH
(和您的)。$MANPATH
As a precaution, the installer will create a backup of the original .profilein case you want to roll back the changes (or if you completely uninstall MacPorts later). Here's an example from a random machine at work.
作为预防措施,安装程序将创建原始.profile的备份,以防您想回滚更改(或者您以后完全卸载 MacPorts)。这是工作中的随机机器的示例。
admin ~ $ ls .profile*
.profile .profile.macports-saved_2009-08-03_at_14:55:56
admin ~ $ ls .profile*
.profile .profile.macports-saved_2009-08-03_at_14:55:56
If you look in .profileyou should see something like this:
如果您查看.profile,您应该会看到如下内容:
##
# Your previous /Users/admin/.profile file was backed up as /Users/admin/.profile.macports-saved_2009-08-03_at_14:55:56
##
# MacPorts Installer addition on 2009-08-03_at_14:55:56: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
# MacPorts Installer addition on 2009-08-03_at_14:55:56: adding an appropriate MANPATH variable for use with MacPorts.
export MANPATH=/opt/local/share/man:$MANPATH
# Finished adapting your MANPATH environment variable for use with MacPorts.
##
# Your previous /Users/admin/.profile file was backed up as /Users/admin/.profile.macports-saved_2009-08-03_at_14:55:56
##
# MacPorts Installer addition on 2009-08-03_at_14:55:56: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
# MacPorts Installer addition on 2009-08-03_at_14:55:56: adding an appropriate MANPATH variable for use with MacPorts.
export MANPATH=/opt/local/share/man:$MANPATH
# Finished adapting your MANPATH environment variable for use with MacPorts.
If your $PATH hasn'tbeen updated, you should adjust it, since otherwise, you will have trouble using the port
tool and the software you install via MacPorts.
如果你的$ PATH还没有被更新,你应该调整它,否则,你将不得不使用麻烦port
的工具,您通过使用MacPorts安装软件。
回答by ayaz
I am inclined to think that macports
usually keeps all of its stuff inside the /opt/local
directory. I am using Leopard, and I have it inside that directory. You may want to look in there, particularly inside /opt/local/bin
, to find the ruby
binary you are looking for.
我倾向于认为macports
通常将所有内容都保存在/opt/local
目录中。我正在使用 Leopard,并将它放在该目录中。您可能想要查看那里,特别是 inside /opt/local/bin
,以找到ruby
您正在寻找的二进制文件。