如何在OS X上正确安装Emacs?

45

我试着做:

brew install emacs --HEAD --use-git-head --with-cocoa --with-gnutls --with-rsvg --with-imagemagick

但是当我执行emacs --version命令时

emacs --version
-bash: /usr/local/Cellar/emacs/24.5/Emacs.app/Contents/MacOS/Emacs: No such file or directory

当我进行

brew info emacs

emacs: stable 25.2 (bottled), HEAD

我是一个EMACS新手。它有点难懂。我可能已经删除了默认的Emacs。


也许不是你想要的,但是可以试着看看AquaMacs。它在OSX上很容易运行。 - Duxducis
@Duxducis 谢谢。我更喜欢运行GNU版本... - maximusdooku
1
明白了,这些是GNU版本的预编译二进制文件,适用于OSX系统。https://emacsformacosx.com/ - Duxducis
Bash 给出的错误提示表明你正在运行的 emacs 是一个包装脚本,它明确地想要运行 /usr/local/Cellar/emacs/24.5/Emacs.app/Contents/MacOS/Emacs。运行 which emacs 应该会告诉你那个包装脚本在哪里。 - phils
7个回答

61

这是针对2019年4月的更新,Mac OSX mojave 10.14.4 reddit上的讨论

看起来在Hombrew中并没有可用的cocoa选项以及--head。因此你可以:

brew cask install emacs #is the preferred from emacs wiki
brew install --cask emacs #using new cask syntax

如果你想在不使用cask的情况下从brew进行相同的设置,可以使用以下命令:

emacs-head

brew tap daviderestivo/emacs-head
brew install emacs-head --HEAD --with-cocoa --with-librsvg --with-imagemagick@7 --with-json --with-multicolor-fonts --with-no-frame-refocus --with-mailutils --with-dbus --with-modules

获取这个

ls -l $(which emacs)                                                                                                                                                                                               
lrwxr-xr-x  1 toni  admin  45 23 abr 19:26 /usr/local/bin/emacs -> ../Cellar/emacs-head/HEAD-259dfd2_1/bin/emacs

然后你可以使用osascript来进入Spotlight和应用程序:

osascript -e 'tell application "Finder" to make alias file to POSIX file "/usr/local/Cellar/emacs-head/HEAD-259dfd2_1/Emacs.app" at POSIX file "/Applications"'

下面的内容已经过时,但仍然包含更多信息: 这是2017年10月的更新。现在,易于安装的emacs正在使用brew cask。

brew cask install emacs

这样做很好,但我在使用gnutls和安装最新的org(9.1.6)时遇到了问题,不过之前都运行良好。

如果您想要传统方式并将emacs更好地集成到您的系统中,或者想要获取夜间版本,您可以使用以下命令进行安装:

brew install emacs --HEAD --with-cocoa --with-gnutls --with-librsvg --with-imagemagick@6 --with-mailutils

--HEAD 不是必需的,现在(2018年1月23日)可以获取 Emacs 27,最新版本已经不需要 HEAD。

然后你应该将其用于 Spotlight:

brew linkapps emacs
rm /Applications/Emacs.app
osascript -e 'tell application "Finder" to make alias file to POSIX file "/usr/local/opt/emacs/Emacs.app" at POSIX file "/Applications"'

最后,看一下emacs wiki

Homebrew has Emacs 25.3 as of October 2017. Cask homebrew installation

Homebrew now recommends to use the cask version with the following message: “Please try the Cask for a better-supported Cocoa version”

To install the cask version:

brew cask install emacs

This installs a pre-built package from https://emacsformacosx.com/ Standard homebrew installation

If you prefer not to run the cask version, you can still use the old homebrew recipe.

A Cocoa-specific Emacs.app can be built using the --with-cocoa switch.
A version supporting X11 can be built using the --with-x switch. Note that this version will not have all of the features of the Cocoa

version; use only if necessary.

Other options include:

--keep-ctags Don’t remove the ctags executable that emacs provides. Use of this flag is not recommended Instead, use brew

install ctags after installation. --srgb This option will enable sRGB colors when using Cocoa.

To install using the --with-cocoa switch, one simply uses:

brew install --with-cocoa emacs

to get some “pretty” colours add the --srgb switch:

brew install --with-cocoa --srgb emacs

and finally link it to your Applications folder:

brew linkapps emacs

This creates a symlink and not an alias. So Spotlight may not find it (tested on macOS Sierra 10.12.2). Spotlight indexes symlinks to files that are treated as system files, but it doesn’t show them in the GUI. It does show aliases though, so you could just command-option-drag /usr/local/Cellar/emacs/*/Emacs.app to /Applications/ from Finder. Or:

$ osascript -e "tell application "Finder" to make alias file to (POSIX file "/usr/local/Cellar/emacs-plus/25.3/Emacs.app") at POSIX file "$HOME/Applications""

After installation, using the emacs command in the terminal or shell will run the -nw version of Emacs. If you want to run the Cocoa version using this command, you simply add a line to your .bash_profile. Emacs-Plus version in tap

To instead use the emacs-plus version, which is like regular homebrew emacs but with some configuration options enabled,

brew tap d12frosted/emacs-plus brew install emacs-plus

Mitsaharu version in tap

To instead use the Yamamoto Mitsuharu version of Emacs 25.2 (with more mac-specific features):

brew tap railwaycat/emacsmacport brew install emacs-mac

and finally link it to your Applications folder:

brew linkapps emacs-mac


30

你不需要向brew传递一些参数来获取最新的emacs 26.1。请尝试以下操作:

卸载emacs

brew uninstall emacs

清除先前下载的源文件

brew cleanup

检查您的Brew安装是否正常

brew doctor

当你运行emacs --version时,出现的消息表明你安装的emacs 24只是部分安装。运行brew doctor应该可以帮助识别问题。

确保你正在运行最新版本的brew。

brew update

如果您手头有任何之前的先决条件,请升级它们。

brew upgrade

然后使用以下命令安装emacs:

brew install emacs --with-cocoa --with-librsvg --with-imagemagick@6

请留意brew发送的信息。在安装过程中,brew会建议运行以下命令:

brew linkapps emacs

确保之后链接到/Applications文件夹的新版本是正确的。我怀疑这可能是您安装过程中缺少的步骤。虽然brew手册建议此命令已弃用,但也建议使用cask版本代替。我发现cask版本存在一些问题,因此更喜欢使用本地构建版本(cask版本使用emacsforosx二进制文件)。当使用非cask版本时是否仍应运行linkapps并不清楚-但是,安装过程应告诉您,请确保查看所有输出(消息不在末尾,而在安装过程输出中较远的位置)。

您提供的其他参数只有在您想要安装最新开发版本时才需要,如果您刚开始使用,这不是一个好主意。您只需要Emacs 26.1

确保/usr/local/bin在/usr/bin之前出现在您的路径中,以避免Emacs引用与OSX捆绑的非常旧版本的Emacs。


5
Linkapps 已经不推荐使用了吗? - maximusdooku
2
我收到了以下警告: 警告:emacs:此公式没有--with-imagemagick选项,因此将被忽略! 警告:emacs:此公式没有--with-rsvg选项,因此将被忽略! - schaary
2
请问您能否就“警告:emacs:此公式没有--with-imagemagick选项,因此将被忽略!”问题发表评论。谢谢。 - Lukas
1
@TimX - 我编辑了你的答案,添加了更新后的参数和一个新的 brew info emacs 步骤,但我的编辑被审核人员拒绝了。如果您能更新您的答案以包含这些更改,我相信其他读者会很感激。 - Melioratus
4
è؟™ه·²ç»ڈè؟‡و—¶ن؛†م€‚ن½؟用brew cask install emacsè؟™ن¸ھه‘½ن»¤م€‚هڈ‚è§پhttps://dev59.com/questions/UVcP5IYBdhLWcg3worZh#47155790م€‚ - bpaul
显示剩余5条评论

19

其实我不知道为什么我们要像其他答案一样做,为什么这篇帖子的答案如此复杂?要在Mac OSX上安装emacs,只需在Mac终端中运行以下命令:

brew install --cask emacs

那么你已经有了最新版本。只需使用它即可。


1
安装emacs的最佳方法是这样的。 - Shukant Pal
同意,但我认为如果你已经有了一个版本的 emacs,那么你也应该将其卸载:brew uninstall emacs - Beth Long

15

2022年更新:

brew install homebrew/cask/emacs

现在在 Mac 上安装 Emacs 的最佳方式。

先前的答案:

您应该能够使用 brew uninstall emacsbrew cleanup 将自己恢复到正常状态。

由于 brew 和 cask 已经合并,现在您可以使用 brew install --cask emacs 来安装。假设您想要安装 GUI。


1
我已经完成了brew cask install emacs的安装,似乎已经安装了emacs 26.1,但是当我调用它时"/usr/local/Cellar.../bin/emacs foo.txt",它没有出现GUI版本,而是终端版本。如何调用并获取GUI版本(Mac OS),以便我仍然可以利用终端?在我的旧Macbook上,这个功能运行得非常好,但它已经毁掉了,所以我知道这应该是可能的。 - Ken
GUI 在 /Applications/Emacs.app/Contents/MacOS/Emacs,这就是符号链接所指向的位置。ls -lah /usr/local/bin/emacs lrwxr-xr-x 1 adamhess admin 44B Aug 21 2017 /usr/local/bin/emacs -> /Applications/Emacs.app/Contents/MacOS/Emacs - HParker

1
使用 brew:
brew install --cask emacs

感谢@Mark McElroy提供的帮助。

之前的回答:

我会从https://emacsformacos.com/安装Emacs

并创建/usr/local/bin/emacs文件,内容如下:

#!/bin/sh
exec /Applications/Emacs.app/Contents/MacOS/Emacs "$@"

最后运行:

chmod 755 /usr/local/bin/emacs

现在你可以从命令行运行emacs


2
brew install --cask emacs 为我安装了来自 https://emacsformacos.com/ 的二进制文件。 - Mark McElroy

0

如果已经安装了home-brew,那么使用命令“brew install emacs”即可在Mac终端上安装emacs。否则,请先使用命令“/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"”安装home-brew。一旦安装了home-brew,就可以使用之前的emacs命令。安装完emacs后,您可以运行“brew services start emacs”来成功启动emacs。


0

我刚刚卸载并重新安装了

brew cask install emacs

可以正常工作,除非你使用org-mode。

进入/Applications/Emacs.app/Contents/Resources/lisp/org

看一下org.el.gz

非常过时的版本9.1.9。

非常令人困惑的是,Org菜单显示的版本是9.3.7,而(org-version)也报告相同的版本。

执行packages-list-packages命令,它会正确地报告9.1.9。

猜猜我浪费了多少时间在这上面?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接