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

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

Getting a Scala interpreter to work

macosshellscalaterminalinstallation

提问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 scalaand scala will be installed and ready to go. Homebrew also has tons of other goodies just a brew installaway.

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.

MacPortsFink可能有类似的东西,但我更喜欢 Homebrew。

回答by Daniel Canas

Not a big fan of cluttering up my PATHvariable. 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 scalain the terminal and you're all set. This way you don't have to set your PATHor 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.1at 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\binto your PATHenvironment variable.

您需要添加scala\bin到您的PATH环境变量中。

On Mac OS X the path to Scala bin is usually: /Users/<your username>/scala/binand 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/binfor sbt, scala, scalac, scaladoc, scalap, fscand g8. Follow the soft links to its final referent in order to determine where $SCALA_HOME needs to be. $SCALA_HOME should contain bin/scalaand lib/scala-compiler.jar.

自制软件将安装软链接/usr/local/binsbtscalascalacscaladocscalapfscg8。按照软链接指向其最终引用,以确定 $SCALA_HOME 需要在哪里。$SCALA_HOME 应该包含bin/scalalib/scala-compiler.jar

Typesafe recommends using sbt consoleinstead of scalato get the interpreter going, because sbtwill also manage library dependencies to libraries such as Akka. That said, if you want to use scala, scalac, fsc, scalacand scaladocdirectly, you may need to run a chmod +xon the referents of the soft links.

Typesafe 建议使用sbt console而不是scala让解释器运行,因为它sbt还将管理库依赖于诸如 Akka 之类的库。这就是说,如果你想使用scalascalacfscscalacscaladoc直接,你可能需要运行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 文件。

  1. Download the latest Scala binary from www.scala-lang.org/download
  2. Unzip the binary file
  3. Move the unzipped folder (named scala-2.11.2) to the /usr/bin/ or some other directory of your preference.
  4. Then open the /etc/paths file with nano:

    sudo nano /etc/paths
    
  5. and add this line to the end:

    /usr/bin/scala-2.11.2/bin
    
  6. Press Ctrl+X to exit nano and answer "Yes" when prompted to overwrite the file

  7. 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> 
    
  1. www.scala-lang.org/download下载最新的 Scala 二进制文件
  2. 解压二进制文件
  3. 将解压后的文件夹(名为 scala-2.11.2)移动到 /usr/bin/ 或您喜欢的其他目录。
  4. 然后用nano打开/etc/paths文件:

    sudo nano /etc/paths
    
  5. 并将这一行添加到最后:

    /usr/bin/scala-2.11.2/bin
    
  6. 按 Ctrl+X 退出 nano 并在提示覆盖文件时回答“是”

  7. 然后重新启动终端,一旦你输入:

    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:

如果您不想在路径中添加更多目录,请尝试以下步骤:

  1. Download Scala from the downloads pages.
  2. Unzip and then copy the folder to \Library\Scala.
  3. Find the complete path to the bin directory, which should be \Library\Scala\scala-2.9.2\bin.
  4. Find the "scala" file, right click, and Make Alias.
  5. Move the alias file anywhere it's convenient, such as your desktop.
  6. Double click the alias to start Scala in the Terminal.
  1. 下载页面下载 Scala 。
  2. 解压缩,然后将文件夹复制到 \Library\Scala。
  3. 找到bin目录的完整路径,应该是\Library\Scala\scala-2.9.2\bin。
  4. 找到“scala”文件,右键单击,然后创建别名。
  5. 将别名文件移动到任何方便的地方,例如桌面。
  6. 双击别名以在终端中启动 Scala。

回答by Seif Tamallah

Just install Scala with : $ brew install scalaso you can use $scalain terminal to evaluate scala instructions , for now the official Scala website recommend installing scala with sbt : $ brew install sbtwhich won't let you scalakeyword 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 山狮)