找一个Scala解释器来工作。

时间:2022-12-11 23:30:31

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 website infuriatingly 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)
  • Mac OS X(10.6.7)
  • Scala: 2.9.0.1
  • Scala:2.9.0.1

Thank you

谢谢你!

7 个解决方案

#1


77  

For OS X, I highly recommend Homebrew.

对于OS X,我强烈推荐Homebrew。

The installation of Homebrew is 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安装scala和scala就可以了。家酿也有很多其他的好东西,只是一种啤酒的安装。

If you don't already have Java installed, you can install that with brew cask install java.

如果您还没有安装Java,您可以使用brew cask安装Java。

MacPorts or Fink may have something similar, but I prefer Homebrew.

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

#2


12  

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.

我不太喜欢弄乱我的路径变量。我只是将我所有的程序都连接到/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,你就可以了,这样你就不用设置你的路径或者在你有一个新的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.

现在,要使用scala2.9.1,您只需在终端运行scala2.9.1。当您准备切换到2.9.1的fulltime时,只需更新symlink。

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

#3


7  

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本通常是: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.

然后关闭终端,再启动它。

#4


5  

Scala recommends using Homebrew to install the Typesafe stack for Scala 2.9.2.

Scala建议使用Homebrew为Scala 2.9.2安装Typesafe堆栈。

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.

Homebrew将在/usr/local/bin中为sbt、scala、scalac、scaladoc、scalap、fsc和g8安装软链接。遵循软链接到它的最终参照,以确定$SCALA_HOME需要在哪里。$SCALA_HOME应该包含bin/scala和lib/scala-compile .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控制台而不是scala来让解释器运行,因为sbt还会管理库的依赖关系,比如Akka等库。也就是说,如果您想要直接使用scala、scalac、fsc、scalac和scaladoc,那么您可能需要在软链接的referents上运行一个chmod +x。

#5


2  

If you don't want to add more directories to your path, try these steps:

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

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

#6


1  

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”时,都要将not to .bashrc文件的路径添加到/etc/path中。

  1. Download the latest Scala binary from www.scala-lang.org/download
  2. 从www.scala-lang.org/download下载最新的Scala二进制文件。
  3. Unzip the binary file
  4. 解压二进制文件
  5. Move the unzipped folder (named scala-2.11.2) to the /usr/bin/ or some other directory of your preference.
  6. 将解压缩的文件夹(名为scala-2.11.2)移到/usr/bin/或您首选的其他目录。
  7. Then open the /etc/paths file with nano:

    然后用nano打开/etc/path文件:

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

    把这条线加到末尾:

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

    按Ctrl+X退出nano,并在提示改写该文件时回答“是”。

  10. Then restart Terminal and once you type:

    然后重启终端,一旦你输入:

    scala
    

    you will get the scala command line that looks like this:

    您将得到这样的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.

我希望这可以帮助。

#7


0  

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 mountain lion来说是这样)

#1


77  

For OS X, I highly recommend Homebrew.

对于OS X,我强烈推荐Homebrew。

The installation of Homebrew is 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安装scala和scala就可以了。家酿也有很多其他的好东西,只是一种啤酒的安装。

If you don't already have Java installed, you can install that with brew cask install java.

如果您还没有安装Java,您可以使用brew cask安装Java。

MacPorts or Fink may have something similar, but I prefer Homebrew.

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

#2


12  

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.

我不太喜欢弄乱我的路径变量。我只是将我所有的程序都连接到/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,你就可以了,这样你就不用设置你的路径或者在你有一个新的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.

现在,要使用scala2.9.1,您只需在终端运行scala2.9.1。当您准备切换到2.9.1的fulltime时,只需更新symlink。

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

#3


7  

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本通常是: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.

然后关闭终端,再启动它。

#4


5  

Scala recommends using Homebrew to install the Typesafe stack for Scala 2.9.2.

Scala建议使用Homebrew为Scala 2.9.2安装Typesafe堆栈。

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.

Homebrew将在/usr/local/bin中为sbt、scala、scalac、scaladoc、scalap、fsc和g8安装软链接。遵循软链接到它的最终参照,以确定$SCALA_HOME需要在哪里。$SCALA_HOME应该包含bin/scala和lib/scala-compile .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控制台而不是scala来让解释器运行,因为sbt还会管理库的依赖关系,比如Akka等库。也就是说,如果您想要直接使用scala、scalac、fsc、scalac和scaladoc,那么您可能需要在软链接的referents上运行一个chmod +x。

#5


2  

If you don't want to add more directories to your path, try these steps:

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

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

#6


1  

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”时,都要将not to .bashrc文件的路径添加到/etc/path中。

  1. Download the latest Scala binary from www.scala-lang.org/download
  2. 从www.scala-lang.org/download下载最新的Scala二进制文件。
  3. Unzip the binary file
  4. 解压二进制文件
  5. Move the unzipped folder (named scala-2.11.2) to the /usr/bin/ or some other directory of your preference.
  6. 将解压缩的文件夹(名为scala-2.11.2)移到/usr/bin/或您首选的其他目录。
  7. Then open the /etc/paths file with nano:

    然后用nano打开/etc/path文件:

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

    把这条线加到末尾:

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

    按Ctrl+X退出nano,并在提示改写该文件时回答“是”。

  10. Then restart Terminal and once you type:

    然后重启终端,一旦你输入:

    scala
    

    you will get the scala command line that looks like this:

    您将得到这样的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.

我希望这可以帮助。

#7


0  

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 mountain lion来说是这样)