Skip to content

Commit be2656d

Browse files
committed
Massively simplify getting started with Scala
1 parent 7ec2ca6 commit be2656d

File tree

2 files changed

+23
-96
lines changed

2 files changed

+23
-96
lines changed

_data/setup-scala.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
linux-x86-64: curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && chmod +x cs && ./cs setup
2-
linux-arm64: curl -fL https://github.com/VirtusLab/coursier-m1/releases/latest/download/cs-aarch64-pc-linux.gz | gzip -d > cs && chmod +x cs && ./cs setup
3-
macOS-x86-64: curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-apple-darwin.gz | gzip -d > cs && chmod +x cs && (xattr -d com.apple.quarantine cs || true) && ./cs setup
4-
macOS-arm64: curl -fL https://github.com/VirtusLab/coursier-m1/releases/latest/download/cs-aarch64-apple-darwin.gz | gzip -d > cs && chmod +x cs && (xattr -d com.apple.quarantine cs || true) && ./cs setup
5-
macOS-brew: brew install coursier && coursier setup
6-
windows-link: https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-win32.zip
1+
macos-linux-cli: curl https://raw.githubusercontent.com/VirtusLab/scala-cli/refs/heads/main/scala-cli.sh > scala && chmod +x scala
2+
windows-cli: Invoke-WebRequest -Uri "https://raw.githubusercontent.com/VirtusLab/scala-cli/refs/heads/main/scala-cli.bat" -OutFile "scala.bat”

_overviews/getting-started/install-scala.md

+21-90
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,25 @@ The instructions below cover both Scala 2 and Scala 3.
3333

3434
{% include inner-documentation-sections.html links=page.newcomer_resources %}
3535

36-
## Install Scala on your computer
36+
## Install the Scala CLI
3737

38-
Installing Scala means installing various command-line tools such as the Scala compiler and build tools.
39-
We recommend using the Scala installer tool "Coursier" that automatically installs all the requirements, but you can still manually install each tool.
38+
### Install Scala in your project
4039

41-
### Using the Scala Installer (recommended way)
42-
43-
The Scala installer is a tool named [Coursier](https://get-coursier.io/docs/cli-overview), whose main command is named `cs`.
44-
It ensures that a JVM and standard Scala tools are installed on your system.
45-
Install it on your system with the following instructions.
40+
Download the Scala CLI launcher in your project directory:
4641

4742
<!-- Display tabs for each OS -->
4843
{% tabs install-cs-setup-tabs class=platform-os-options %}
4944

50-
<!-- macOS -->
51-
{% tab macOS for=install-cs-setup-tabs %}
45+
<!-- macOS/Linux -->
46+
{% tab macOS/Linux for=install-cs-setup-tabs %}
5247
Run the following command in your terminal, following the on-screen instructions:
53-
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-brew %}
54-
{% altDetails cs-setup-macos-nobrew "Alternatively, if you don't use Homebrew:" %}
55-
On the Apple Silicon (M1, M2, …) architecture:
56-
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-arm64 %}
57-
Otherwise, on the x86-64 architecture:
58-
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-x86-64 %}
59-
{% endaltDetails %}
60-
{% endtab %}
61-
<!-- end macOS -->
62-
63-
<!-- Linux -->
64-
{% tab Linux for=install-cs-setup-tabs %}
65-
Run the following command in your terminal, following the on-screen instructions.
66-
67-
On the x86-64 architecture:
68-
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.linux-x86-64 %}
69-
Otherwise, on the ARM64 architecture:
70-
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.linux-arm64 %}
48+
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macos-linux-cli %}
7149
{% endtab %}
72-
<!-- end Linux -->
50+
<!-- end macOS/Linux -->
7351

7452
<!-- Windows -->
7553
{% tab Windows for=install-cs-setup-tabs %}
76-
Download and execute [the Scala installer for Windows]({{site.data.setup-scala.windows-link}})
77-
based on Coursier, and follow the on-screen instructions.
54+
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.windows-cli %}
7855
{% endtab %}
7956
<!-- end Windows -->
8057

@@ -83,67 +60,21 @@ Run the following command in your terminal, following the on-screen instructions
8360
<noscript>
8461
<p><span style="font-style:italic;">JavaScript is disabled, click the tab relevant for your OS.</span></p>
8562
</noscript>
86-
Follow the documentation from Coursier on
87-
[how to install and run `cs setup`](https://get-coursier.io/docs/cli-installation).
63+
Follow the documentation from the Scala CLI on
64+
[how to install and run `scala`](https://scala-cli.virtuslab.org/install).
8865
{% endtab %}
8966
<!-- end Other -->
9067

9168
{% endtabs %}
9269
<!-- End tabs -->
9370

94-
> <i class="fa fa-info"></i>&nbsp;&nbsp; You may need to restart your terminal, log out,
95-
> or reboot in order for the changes to take effect.
96-
{: .help-info}
97-
98-
<!-- Alternative Detail - test the `scala` command -->
99-
{% altDetails testing-your-setup 'Testing your setup' %}
100-
Check your setup with the command `scala -version`, which should output:
101-
```bash
102-
$ scala -version
103-
Scala code runner version: 1.4.3
104-
Scala version (default): {{site.scala-3-version}}
105-
```
106-
{% endaltDetails %}
107-
<!-- end Alternative Detail -->
108-
109-
110-
Along with managing JVMs, `cs setup` also installs useful command-line tools:
111-
112-
| Commands | Description |
113-
|----------|-------------|
114-
| `scalac` | the Scala compiler |
115-
| `scala`, `scala-cli` | [Scala CLI](https://scala-cli.virtuslab.org), interactive toolkit for Scala |
116-
| `sbt`, `sbtn` | The [sbt](https://www.scala-sbt.org/) build tool |
117-
| `amm` | [Ammonite](https://ammonite.io/) is an enhanced REPL |
118-
| `scalafmt` | [Scalafmt](https://scalameta.org/scalafmt/) is the Scala code formatter |
119-
120-
For more information about `cs`, read
121-
[coursier-cli documentation](https://get-coursier.io/docs/cli-overview).
122-
123-
> `cs setup` installs the Scala 3 compiler and runner by default (the `scalac` and
124-
> `scala` commands, respectively). Whether you intend to use Scala 2 or 3,
125-
> this is usually not an issue because most projects use a build tool that will
126-
> use the correct version of Scala irrespective of the one installed "globally".
127-
> Nevertheless, you can always launch a specific version of Scala using
128-
> ```
129-
> $ cs launch scala:{{ site.scala-version }}
130-
> $ cs launch scalac:{{ site.scala-version }}
131-
> ```
132-
> If you prefer Scala 2 to be run by default, you can force that version to be installed with:
133-
> ```
134-
> $ cs install scala:{{ site.scala-version }} scalac:{{ site.scala-version }}
135-
> ```
136-
137-
### ...or manually
138-
139-
You only need two tools to compile, run, test, and package a Scala project: Java 8 or 11,
140-
and Scala CLI.
141-
To install them manually:
142-
143-
1. if you don't have Java 8 or 11 installed, download
144-
Java from [Oracle Java 8](https://www.oracle.com/java/technologies/javase-jdk8-downloads.html), [Oracle Java 11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html),
145-
or [AdoptOpenJDK 8/11](https://adoptopenjdk.net/). Refer to [JDK Compatibility](/overviews/jdk-compatibility/overview.html) for Scala/Java compatibility detail.
146-
1. Install [Scala CLI](https://scala-cli.virtuslab.org/install)
71+
We recommend committing the scala executable together with your code so that
72+
everyone working on the project can compile and run the code without needing to install anything (not even Java).
73+
74+
### ...or/and install Scala on your computer
75+
76+
Follow the documentation from the Scala CLI on
77+
[how to install and run `scala`](https://scala-cli.virtuslab.org/install).
14778

14879
## Using the Scala CLI
14980

@@ -164,7 +95,7 @@ string to standard output.
16495
To run the program, execute `scala run hello.scala` command from a terminal, within the `<project-dir>` directory. The file will be compiled and executed, with console output
16596
similar to following:
16697
```
167-
$ scala run hello.scala
98+
$ ./scala run hello.scala
16899
Compiling project (Scala {{site.scala-3-version}}, JVM (20))
169100
Compiled project (Scala {{site.scala-3-version}}, JVM (20))
170101
Hello, World!
@@ -187,7 +118,7 @@ the content of the `name` argument.
187118

188119
To pass the arguments when executing the program, put them after `--`:
189120
```
190-
$ scala run hello.scala -- Gabriel
121+
$ ./scala run hello.scala -- Gabriel
191122
Compiling project (Scala {{site.scala-3-version}}, JVM (20))
192123
Compiled project (Scala {{site.scala-3-version}}, JVM (20))
193124
Hello, Gabriel!
@@ -216,7 +147,7 @@ sequence of paths.
216147

217148
Execute the program. The dependency will be automatically downloaded. The execution should result in a similar output:
218149
```
219-
$ scala run counter.scala
150+
$ ./scala run counter.scala
220151
Compiling project (Scala {{site.scala-3-version}}, JVM (20))
221152
Compiled project (Scala {{site.scala-3-version}}, JVM (20))
222153
4
@@ -243,7 +174,7 @@ This program is identical to the one above. However, other toolkit libraries wil
243174

244175
You can execute code interactively using the REPL provided by the `scala` command. Execute `scala` in the console without any arguments.
245176
```
246-
$ scala
177+
$ ./scala
247178
Welcome to Scala {{site.scala-3-version}} (20-ea, Java OpenJDK 64-Bit Server VM).
248179
Type in expressions for evaluation. Or try :help.
249180

0 commit comments

Comments
 (0)