macos 如何在 Mac OS X 上安装 Apache Ant?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3222804/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:03:26  来源:igfitidea点击:

How can I install Apache Ant on Mac OS X?

apacheantmacos

提问by florinmatinca

I tried to install Apache Ant on my Mac and I followed the next steps :

我尝试在 Mac 上安装 Apache Ant,然后按照以下步骤操作:

  1. I downloaded apache-ant-1.8.1-bin.tar.gzinto my Downloads folder.
  2. I moved the file to /usr/local/using this commands : sudo shand mv apache-ant-1.8.1-bin.tar.gz /usr/local/
  1. 我下载apache-ant-1.8.1-bin.tar.gz到我的下载文件夹中。
  2. 我将文件移动到/usr/local/使用以下命令:sudo shmv apache-ant-1.8.1-bin.tar.gz /usr/local/

Now I want to use cd /usr/local/but it's not working, I get back "No such file or directory".

现在我想使用cd /usr/local/但它不起作用,我得到“没有这样的文件或目录”。

Then I used cd /usr/and lscommands and it seems that the local folder is there. If I try to access it I get the same error.

然后我使用cd /usr/ls命令,似乎本地文件夹在那里。如果我尝试访问它,我会收到同样的错误。

Since I already used sudo suwhy I can't access it? Any ideas?

既然已经用过了,sudo su为什么进不去?有任何想法吗?

回答by Michael Aaron Safyan

Ant is already installed on some older versions of Mac OS X, so you should run ant -versionto test if it is installed before attempting to install it.

Ant 已经安装在一些较旧版本的 Mac OS X 上,因此您应该ant -version在尝试安装之前运行以测试它是否已安装。

If it is not already installed, then your best bet is to install Homebrew(brew install ant) or MacPorts(sudo port install apache-ant), and use those tools to install Apache Ant.

如果尚未安装,那么最好的办法是安装Homebrew( brew install ant) 或MacPorts( sudo port install apache-ant),并使用这些工具安装 Apache Ant。

Alternatively, though I would highly advise using Homebrew or MacPorts instead, you can install Apache Ant manually. To do so, you would need to:

或者,虽然我强烈建议改用 Homebrew 或 MacPorts,但您可以手动安装 Apache Ant。为此,您需要:

  1. Decompress the .tar.gz file.
  2. Optionally put it somewhere.
  3. Put the "bin" subdirectory in your path.
  1. 解压 .tar.gz 文件。
  2. 可选地把它放在某个地方。
  3. 将“bin”子目录放在您的路径中。

The commands that you would need, assuming apache-ant-1.8.1-bin.tar.gz(replace 1.8.1 with the actual version) were still in your Downloads directory, would be the following (explanatory comments included):

假设apache-ant-1.8.1-bin.tar.gz(用实际版本替换 1.8.1)仍在您的下载目录中,您需要的命令如下(包括解释性注释):

cd ~/Downloads # Let's get into your downloads folder.
tar -xvzf apache-ant-1.8.1-bin.tar.gz # Extract the folder
sudo mkdir -p /usr/local # Ensure that /usr/local exists
sudo cp -rf apache-ant-1.8.1-bin /usr/local/apache-ant # Copy it into /usr/local
# Add the new version of Ant to current terminal session
export PATH=/usr/local/apache-ant/bin:"$PATH"
# Add the new version of Ant to future terminal sessions
echo 'export PATH=/usr/local/apache-ant/bin:"$PATH"' >> ~/.profile
# Verify new version of ant
ant -version

回答by TheIT

For MacOS Maveriks (10.9 and perhaps later versions too), Apache Ant does not come bundled with the operating system and so must be installed manually. You can use brew to easily install ant. Simply execute the following command in a terminal window to install brew:

对于 MacOS Maveriks(10.9 或更高版本),Apache Ant 未与操作系统捆绑在一起,因此必须手动安装。您可以使用 brew 轻松安装 ant。只需在终端窗口中执行以下命令即可安装 brew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

It's a medium sized download which took me 10min to download and install. Just follow the process which involves installing various components. If you already have brew installed, make sure it's up to date by executing:

这是一个中等大小的下载,我花了 10 分钟来下载和安装。只需按照涉及安装各种组件的过程进行操作即可。如果您已经安装了 brew,请通过执行以下命令确保它是最新的:

brew update

Once installed you can simply type:

安装后,您只需键入:

brew install ant

Ant is now installed and available through the "ant" command in the terminal.

Ant 现在已安装并可以通过终端中的“ant”命令使用。

To test the installation, just type "ant -version" into a terminal window. You should get the following output:

要测试安装,只需ant -version在终端窗口中键入“ ”。你应该得到以下输出:

Apache Ant(TM) version X.X.X compiled on MONTH DAY YEAR

Apache Ant(TM) 版本 XXX 编译于 MONTH DAY YEAR

Source: Error executing command 'ant' on Mac OS X 10.9 Mavericks when building for Android with PhoneGap/Cordova

来源:使用 PhoneGap/Cordova 为 Android 构建时,在 Mac OS X 10.9 Mavericks 上执行命令“ant”时出错

If you are getting errors installing Brew, try uninstalling first using the command:

如果您在安装 Brew 时遇到错误,请先尝试使用以下命令卸载:

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

Thanks to OrangeDog and other users for providing additional information.

感谢 OrangeDog 和其他用户提供更多信息。

回答by Karl von Moor

If you have MacPorts installed (https://www.macports.org/), do this:

如果您安装了 MacPorts ( https://www.macports.org/),请执行以下操作:

sudo port install apache-ant

回答by jonfuller

If you're a homebrew user instead of macports, homebrew has an ant recipe.

如果您是 homebrew 用户而不是 macports,那么 homebrew 有一个 ant 配方。

brew install ant

brew install ant

回答by Akalonda

To get Ant running on your Mac in 5 minutes, follow these steps.

要在 5 分钟内让 Ant 在您的 Mac 上运行,请按照以下步骤操作。

Open up your terminal.

打开你的终端。

Perform these commands in order:

按顺序执行这些命令:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install ant

brew install ant

If you don't have Java installed yet, you will get the following error: "Error: An unsatisfied requirement failed this build." Run this command next: brew cask install javato fix this.

如果您尚未安装 Java,您将收到以下错误:“错误:此构建失败的未满足要求。” 接下来运行此命令: brew cask install java修复此问题。

The installation will resume.

安装将继续。

Check your version of by running this command:

通过运行以下命令检查您的版本:

ant -version

ant -version

And you're ready to go!

你准备好了!

回答by SRajpoot

Use Brew is always good way to install ANT and other needs. To install type below command on terminal.

使用 Brew 始终是安装 ANT 和其他需求的好方法。要在终端上安装以下命令。

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

after Brew installation , type

Brew安装后,输入

brew install ant

This will install Ant on your system. Also you will not need to worry about setting up the path.

这将在您的系统上安装 Ant。此外,您无需担心设置路径。

Also i have documented on the same - How to Install ANT on Mac OS?

我也有同样的记录 -如何在 Mac OS 上安装 ANT?

回答by ncmathsadist

MacPorts will install ant for you in MacOSX 10.9. Just use

MacPorts 将在 MacOSX 10.9 中为您安装 ant。只需使用

$ sudo port install apache-ant

and it will install.

它会安装。

回答by Akshay

The only way i could get my ant version updated on the mac from 1.8.2 to 1.9.1 was by following instructions here

我可以在 Mac 上将我的 ant 版本从 1.8.2 更新到 1.9.1 的唯一方法是按照此处的说明进行操作

http://wiki.eclipse.org/Ant/User_Guide

http://wiki.eclipse.org/Ant/User_Guide