macos 让 Scala 解释器工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6230511/
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
Getting a Scala interpreter to work
提问by Alex
I'm very new to Scala. I have downloaded it, got it working in Eclipse where I'll be developing it; but I can't make it work in Terminal.
我对 Scala 很陌生。我已经下载了它,让它在 Eclipse 中运行,我将在那里开发它;但我不能让它在终端中工作。
All sites and books say to just type scala
- this doesn't work.
所有网站和书籍都说只需输入scala
- 这不起作用。
The websiteinfuriatingly says:
该网站令人气愤地说:
We assume that both the Scala software and the user environment are set up correctly.
我们假设 Scala 软件和用户环境都设置正确。
How do I do that bit?
我该怎么做?
I'm very new to this, and using Jargon or assuming too much knowledge of frameworks around Scala will ruin a good response; please keep it simple.
我对此很陌生,使用术语或假设过多的 Scala 框架知识会破坏良好的响应;请保持简单。
- Mac OS X (10.6.7)
- Scala: 2.9.0.1
- Mac OS X (10.6.7)
- 斯卡拉:2.9.0.1
Thank you
谢谢
回答by leedm777
For OS X, I highly recommend Homebrew.
对于 OS X,我强烈推荐Homebrew。
The installation of Homebrewis incredibly easy. Once installed, you just need to run brew install scala
and scala will be installed and ready to go. Homebrew also has tons of other goodies just a brew install
away.
Homebrew的安装非常简单。安装后,您只需要运行brew install scala
,scala 就会安装并准备就绪。Homebrew 还有很多其他的好东西brew install
。
If you don't already have Java installed, you can install that with brew cask install java
.
如果您尚未安装 Java,则可以使用brew cask install java
.
MacPortsor Finkmay have something similar, but I prefer Homebrew.
回答by Daniel Canas
Not a big fan of cluttering up my PATH
variable. I just symlink all my programs to /usr/local/bin, which is in the classpath. For example, if you downloaded scala and uncompress it in /opt/scala-2.9.0-1, run the following in the terminal.
不太喜欢弄乱我的PATH
变量。我只是将我所有的程序符号链接到类路径中的 /usr/local/bin。例如,如果您下载了 scala 并在 /opt/scala-2.9.0-1 中解压,请在终端中运行以下命令。
ln -s /opt/scala-2.9.0-1/bin/scala /usr/local/bin
Now just type scala
in the terminal and you're all set.
This way you don't have to set your PATH
or change it when you have a new version of scala you want to try out. If you download a new version, you can uncompress it in any location and symlink the new version. Say you download version 2.9.1 and uncompress it in /opt/scala-2.9.1. You can type the following in the terminal
现在只需scala
在终端中输入即可。这样PATH
,当您想要尝试使用新版本的 Scala 时,您就不必设置或更改它。如果您下载新版本,您可以在任何位置解压缩它并符号链接新版本。假设您下载了 2.9.1 版并在 /opt/scala-2.9.1 中解压它。您可以在终端中输入以下内容
ln -s /opt/scala-2.9.1/bin/scala /usr/local/bin/scala2.9.1
Now, to use scala 2.9.1 you just run scala2.9.1
at the terminal.
When you are ready to switch to 2.9.1 fulltime, just update the symlink.
现在,要使用 scala 2.9.1,您只需scala2.9.1
在终端上运行即可。当您准备好全职切换到 2.9.1 时,只需更新符号链接即可。
You could also add scaladoc, scalac, scalap and others in the same way
你也可以用同样的方式添加 scaladoc、scalac、scalap 等
ln -s /opt/scala-2.9.0-1/bin/scalac /usr/local/bin
ln -s /opt/scala-2.9.0-1/bin/scalap /usr/local/bin
ln -s /opt/scala-2.9.0-1/bin/scaladoc /usr/local/bin
ln -s /opt/scala-2.9.0-1/bin/fsc /usr/local/bin
ln -s /opt/scala-2.9.0-1/bin/sbaz /usr/local/bin
ln -s /opt/scala-2.9.0-1/bin/sbaz-setup /usr/local/bin
回答by Jonas
You need to add scala\bin
to your PATH
environment variable.
您需要添加scala\bin
到您的PATH
环境变量中。
On Mac OS X the path to Scala bin is usually: /Users/<your username>/scala/bin
and on Windows usually: C:\Program Files (x86)\scala\bin
.
在 Mac OS X 上,Scala bin 的路径通常是:/Users/<your username>/scala/bin
在 Windows 上通常是:C:\Program Files (x86)\scala\bin
.
On Mac OS X use the Terminal and write (using your username):
在 Mac OS X 上,使用终端并写入(使用您的用户名):
echo 'export PATH=/Users/<your username>/scala/bin:$PATH' >> ~/.bash_profile
then close the Terminal and start it again.
然后关闭终端并重新启动它。
回答by Alan
Scala recommends using Homebrew to install the Typesafe stack for Scala 2.9.2.
Scala 建议使用 Homebrew 为 Scala 2.9.2 安装类型安全堆栈。
brew install scala sbt maven giter8
Homebrew will install soft links in /usr/local/bin
for sbt
, scala
, scalac
, scaladoc
, scalap
, fsc
and g8
. Follow the soft links to its final referent in order to determine where $SCALA_HOME needs to be. $SCALA_HOME should contain bin/scala
and lib/scala-compiler.jar
.
自制软件将安装软链接/usr/local/bin
为sbt
,scala
,scalac
,scaladoc
,scalap
,fsc
和g8
。按照软链接指向其最终引用,以确定 $SCALA_HOME 需要在哪里。$SCALA_HOME 应该包含bin/scala
和lib/scala-compiler.jar
。
Typesafe recommends using sbt console
instead of scala
to get the interpreter going, because sbt
will also manage library dependencies to libraries such as Akka. That said, if you want to use scala
, scalac
, fsc
, scalac
and scaladoc
directly, you may need to run a chmod +x
on the referents of the soft links.
Typesafe 建议使用sbt console
而不是scala
让解释器运行,因为它sbt
还将管理库依赖于诸如 Akka 之类的库。这就是说,如果你想使用scala
,scalac
,fsc
,scalac
和scaladoc
直接,你可能需要运行chmod +x
的软链接的所指。
回答by consuela
My way of making Scala run every time you type "scala" in Terminal was to add the path not to the .bashrc file but to the /etc/paths one.
每次在终端中键入“scala”时,我让 Scala 运行的方法是将路径添加到 /etc/paths 文件而不是 .bashrc 文件。
- Download the latest Scala binary from www.scala-lang.org/download
- Unzip the binary file
- Move the unzipped folder (named scala-2.11.2) to the /usr/bin/ or some other directory of your preference.
Then open the /etc/paths file with nano:
sudo nano /etc/paths
and add this line to the end:
/usr/bin/scala-2.11.2/bin
Press Ctrl+X to exit nano and answer "Yes" when prompted to overwrite the file
Then restartTerminal and once you type:
scala
you will get the scala command line that looks like this:
Welcome to Scala version 2.11.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_05). Type in expressions to have them evaluated. Type :help for more information. scala>
- 从www.scala-lang.org/download下载最新的 Scala 二进制文件
- 解压二进制文件
- 将解压后的文件夹(名为 scala-2.11.2)移动到 /usr/bin/ 或您喜欢的其他目录。
然后用nano打开/etc/paths文件:
sudo nano /etc/paths
并将这一行添加到最后:
/usr/bin/scala-2.11.2/bin
按 Ctrl+X 退出 nano 并在提示覆盖文件时回答“是”
然后重新启动终端,一旦你输入:
scala
您将获得如下所示的 scala 命令行:
Welcome to Scala version 2.11.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_05). Type in expressions to have them evaluated. Type :help for more information. scala>
I hope this helps.
我希望这有帮助。
回答by james.garriss
If you don't want to add more directories to your path, try these steps:
如果您不想在路径中添加更多目录,请尝试以下步骤:
- Download Scala from the downloads pages.
- Unzip and then copy the folder to \Library\Scala.
- Find the complete path to the bin directory, which should be \Library\Scala\scala-2.9.2\bin.
- Find the "scala" file, right click, and Make Alias.
- Move the alias file anywhere it's convenient, such as your desktop.
- Double click the alias to start Scala in the Terminal.
- 从下载页面下载 Scala 。
- 解压缩,然后将文件夹复制到 \Library\Scala。
- 找到bin目录的完整路径,应该是\Library\Scala\scala-2.9.2\bin。
- 找到“scala”文件,右键单击,然后创建别名。
- 将别名文件移动到任何方便的地方,例如桌面。
- 双击别名以在终端中启动 Scala。
回答by Seif Tamallah
Just install Scala with : $ brew install scala
so you can use $scala
in terminal to evaluate scala instructions , for now the official Scala website recommend installing scala with sbt : $ brew install sbt
which won't let you scala
keyword in terminal
只需使用 : 安装 Scala,$ brew install scala
这样您就可以$scala
在终端中使用来评估 scala 指令,目前 Scala 官方网站建议使用 sbt 安装 Scala:$ brew install sbt
这不会让您scala
在终端中使用关键字
回答by Christos
If you downloaded scala with macports try typing scala-2.9 (or whatever is the filename of the contents of folder /opt/local/bin/scala/)
如果您使用 macports 下载了 scala,请尝试输入 scala-2.9(或文件夹 /opt/local/bin/scala/ 的内容的文件名)
(At least this works for OSX mountain lion)
(至少这适用于 OSX 山狮)