WSL2下Ubuntu中的Scala环境安装
sudo sed -i 's/http:\/\/archive.ubuntu.com/https:\/\/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
sudo apt update && sudo apt upgrade -y
sudo apt install openjdk-17-jdk -y
vi ~/.profile
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
export COURSIER_REPOSITORIES="ivy2Local|central|sonatype:releases|jitpack|https://corporate.com/repo"
source ~/.profile
which java
curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && chmod +x cs
./cs setup
https://github.com/coursier/coursier/releases/download/v2.1.8/cs-x86_64-pc-linux.gz
\\wsl.localhost\Ubuntu-22.04\home\cc\.cache\coursier\v1\https\github.com\coursier\coursier\releases\download\v2.1.8\cs-x86_64-pc-linux.gz
\\wsl.localhost\Ubuntu-22.04\home\cc\.cache\coursier\v1\https\github.com\VirtusLab\scala-cli\releases\download\v1.1.1\scala-cli-x86_64-pc-linux.gz
https://github.com/sbt/sbt/releases/download/v1.9.8/sbt-1.9.8.zip
\\wsl.localhost\Ubuntu-22.04\home\cc\.cache\coursier\v1\https\github.com\sbt\sbt\releases\download\v1.9.8\sbt-1.9.8.zip
./cs list
./cs update
./cs update scala
./cs install scala:3.3.1 && cs install scalac:3.3.1
./cs launch scalaa:3.3.1
./cs java --installed
# https://github.com/adoptium/temurin17-binaries
./cs java --jvm 17
vi ~/.sbt/repositories
[repositories]
local
aliyunmaven: https://maven.aliyun.com/repository/public
central-repos1: https://repo1.maven.org/maven2/
mkdir -p /mnt/d/Study/ScalaProjects && cd $_
sbt new scala/scala3.g8
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
A template to demonstrate a minimal Scala 3 application
name [Scala 3 Project Template]: hello-scala3
Template applied in /mnt/d/Study/ScalaProjects/./hello-scala3
cd hello-scala3/
vi /mnt/d/Study/ScalaProjects/hello-scala3/project/build.properties
sbt.version=1.9.7 -> 1.9.8
sbt run
sbt new scala/hello-world.g8
vi /mnt/d/Study/ScalaProjects/hello-scala2/project/build.properties
sbt.version=1.9.7 -> 1.9.8
vi /mnt/d/Study/ScalaProjects/hello-scala2/build.sbt
scalaVersion := 2.13.12
cd /mnt/d/Study/ScalaProjects/hello-scala2
sbt run
cd /mnt/d/Study/ScalaProjects
sbt new playframework/play-scala-seed.g8
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
This template generates a Play Scala project
name [play-scala-seed]: hello-play
organization [com.example]: org.penguin
play_version [3.0.1]:
scala_version [2.13.12]:
sbt_giter8_scaffold_version [0.16.2]:
Template applied in /mnt/d/Study/ScalaProjects/./hello-play
cd hello-play/
sbt run
由于国内的网络问题,安装比较费时间,在安装好后,可用执行如下命令备份或恢复安装环境。
tar --xattrs --xattrs-include=* -zcvf scala-env.tar.gz .cache .config .g8 .ivy2 .local .sbt cs hello-scala3 .motd_shown
tar --xattrs --xattrs-include=* -zxvf scala-env.tar.gz
参考: