简体   繁体   English

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

[英]How can I install Apache Ant on Mac OS X?

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.gz into my Downloads folder.我将apache-ant-1.8.1-bin.tar.gz下载到我的下载文件夹中。
  2. I moved the file to /usr/local/ using this commands : sudo sh and mv apache-ant-1.8.1-bin.tar.gz /usr/local/我使用以下命令将文件移动到/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 ls commands and it seems that the local folder is there.然后我使用cd /usr/ls命令,似乎本地文件夹在那里。 If I try to access it I get the same error.如果我尝试访问它,我会收到同样的错误。

Since I already used sudo su why I can't access it?既然我已经使用了sudo su为什么我无法访问它? Any ideas?有任何想法吗?

Ant is already installed on some older versions of Mac OS X, so you should run ant -version to 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.或者,虽然我强烈建议改用 Homebrew 或 MacPorts,但您可以手动安装 Apache Ant。 To do so, you would need to:为此,您需要:

  1. Decompress the .tar.gz file.解压 .tar.gz 文件。
  2. Optionally put it somewhere.可选地把它放在某个地方。
  3. Put the "bin" subdirectory in your path.将“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

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.对于 MacOS Maveriks(10.9 或更高版本),Apache Ant 未与操作系统捆绑在一起,因此必须手动安装。 You can use brew to easily install ant.您可以使用 brew 轻松安装 ant。 Simply execute the following command in a terminal window to install brew:只需在终端窗口中执行以下命令即可安装 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.这是一个中等大小的下载,我花了 10 分钟来下载和安装。 Just follow the process which involves installing various components.只需按照涉及安装各种组件的过程进行操作即可。 If you already have brew installed, make sure it's up to date by executing:如果您已经安装了 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.要测试安装,只需在终端窗口中输入“ ant -version ”即可。 You should get the following output:你应该得到以下输出:

Apache Ant(TM) version XXX 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 和其他用户提供更多信息。

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

sudo port install apache-ant

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

brew install ant

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

If you don't have Java installed yet, you will get the following error: "Error: An unsatisfied requirement failed this build."如果您尚未安装 Java,您将收到以下错误:“错误:此构建失败的未满足要求。” Run this command next: brew cask install java to fix this.接下来运行此命令: brew cask install java来解决这个问题。

The installation will resume.安装将继续。

Check your version of by running this command:通过运行以下命令检查您的版本:

ant -version

And you're ready to go!你准备好了!

Use Brew is always good way to install ANT and other needs.使用 Brew 始终是安装 ANT 和其他需求的好方法。 To install type below command on terminal.要在终端上安装以下命令。

/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.这将在您的系统上安装 Ant。 Also you will not need to worry about setting up the path.此外,您无需担心设置路径。

Also i have documented on the same - How to Install ANT on Mac OS?我也有同样的记录 - 如何在 Mac OS 上安装 ANT?

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

MacPorts will install ant for you in MacOSX 10.9. MacPorts 将在 MacOSX 10.9 中为您安装 ant。 Just use只需使用

$ sudo port install apache-ant

and it will install.它会安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM