前置要求

进入~/目录,查看是否存在.bash_profile文件,若不存在,则创建,在最后添加export PATH
修改~/.zshrc文件,在最后一行添加source ~/.bash_profile

解释:
在配置环境变量中,我们通常编辑/etc/profile,但是这是系统级别的文件,最好的方式是编辑用户级别的配置文件,即~/.bash_profile,但是在Mac中,开启终端时加载的是~/.zshrc,所以需要在~/.zshrc最后一行添加一条编译~/.bash_profile的命令,即source ~/.bash_profile

而配置完环境变量之后,需要将环境变量暴露,所以需要在.bash_profile的最后,将PATH暴露,即export PATH

当然也可以直接写在~/.zshrc中。

Java

前往Oracle官网下载JDK:官网

1.oracle官网

下载完成之后直接一路傻瓜式安装。安装完成之后就可以使用java``javac``java -version等命令了。
正常情况下,安装完成后JDK的目录在/Library/Java/JavaVirtualMachines/jdkXXX.jdk/Contents/Home(其中XXX是JDK的版本号)下,编辑~/.bash_profile文件:

  1. JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_333.jdk/Contents/Home
  2. CLASS_PATH="$JAVA_HOME/lib"
  3. PATH=".$PATH:$JAVA_HOME/bin"
  4. export JAVA_HOME
  5. export PATH
  6. export CLASS_PATH

然后执行source ~/.bash_profile即可。

Python

前往官网下载自己需要的版本:官网

下载完成后一路傻瓜式安装即可。
通常Python的安装目录在/Library/Frameworks/Python.framework/Versions/3.9/(其中3.9是安装的版本号)下,进入bin目录,找到对应的Python可执行文件,并配置环境变量:

2.寻找python可执行文件

  1. PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
  2. alias python39="/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9"
  3. alias pip39="/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9"

执行source ~/.bash_profile,并执行python39 -Vpip39 -V检查是否可用。

Node

使用nvm工具安装nodejs
执行下面任意一条命令即可安装nvm

  1. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
  2. wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash

~/.bash_profile中配置:

  1. # nvm (安装node的工具)
  2. export NVM_DIR="$HOME/.nvm"
  3. [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  4. [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
  5. # nvm 国内镜像
  6. export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node
  7. export NVM_IOJS_ORG_MIRROR=http://npm.taobao.org/mirrors/iojs

执行source ~/.bash_profile,然后就可以通过nvm工具安装nodejs了,常用命令如下:

  1. nvm ls-remote # 列出所有可用版本
  2. nvm install <version> # 安装指定版本
  3. nvm uninstall <version> # 卸载指定版本
  4. nvm ls # 列出所有安装版本
  5. nvm use <version> # 切换使用指定的版本
  6. nvm current # 显示当前使用的版本
  7. nvm alias default <version> # 设置默认的node版本
  8. nvm deactivate # 解除当前版本绑定

使用nvm工具安装的node,其目录在~/.nvm/versions/node/

执行nvm install 12,等待安装完成后,执行node -vnpm -v检查是否可用。

但是在后续运行vue项目的时候发现了如下报错:

  1. /Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/npm run dev
  2. > vue-manage-system@5.1.0 dev /Users/zhinushannan/code/wanxiao_reported/vue-manage-system
  3. > vite
  4. <--- Last few GCs --->
  5. [38157:0x120008000] 45 ms: Scavenge 9.6 (11.8) -> 9.3 (14.6) MB, 0.3 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
  6. [38157:0x120008000] 53 ms: Scavenge 11.4 (14.6) -> 10.8 (19.6) MB, 0.4 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
  7. [38157:0x120008000] 84 ms: Scavenge 14.9 (20.4) -> 13.3 (21.4) MB, 0.6 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
  8. <--- JS stacktrace --->
  9. FATAL ERROR: wasm code commit Allocation failed - process out of memory
  10. 1: 0x10485bf24 node::Abort() [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  11. 2: 0x10485c088 node::OnFatalError(char const*, char const*) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  12. 3: 0x104984754 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  13. 4: 0x1049846d4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  14. 5: 0x104eeb1d4 v8::internal::wasm::WasmCodeManager::TryAllocate(unsigned long, void*) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  15. 6: 0x104eebfe0 v8::internal::wasm::NativeModule::CreateEmptyJumpTableInRegion(unsigned int, v8::base::AddressRegion) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  16. 7: 0x104eeb49c v8::internal::wasm::NativeModule::AddCodeSpace(v8::base::AddressRegion) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  17. 8: 0x104eebe28 v8::internal::wasm::NativeModule::NativeModule(v8::internal::wasm::WasmEngine*, v8::internal::wasm::WasmFeatures const&, bool, v8::internal::VirtualMemory, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, std::__1::shared_ptr<v8::internal::Counters>, std::__1::shared_ptr<v8::internal::wasm::NativeModule>*) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  18. 9: 0x104eee39c v8::internal::wasm::WasmCodeManager::NewNativeModule(v8::internal::wasm::WasmEngine*, v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, unsigned long, bool, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  19. 10: 0x104ef4c88 v8::internal::wasm::WasmEngine::NewNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, unsigned long, bool, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  20. 11: 0x104ef4bcc v8::internal::wasm::WasmEngine::NewNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  21. 12: 0x104ecc36c v8::internal::wasm::AsyncCompileJob::CreateNativeModule(std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  22. 13: 0x104ed55d0 v8::internal::wasm::AsyncCompileJob::PrepareAndStartCompile::RunInForeground(v8::internal::wasm::AsyncCompileJob*) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  23. 14: 0x104ed5e4c v8::internal::wasm::AsyncCompileJob::CompileTask::RunInternal() [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  24. 15: 0x1048bdfbc node::PerIsolatePlatformData::RunForegroundTask(std::__1::unique_ptr<v8::Task, std::__1::default_delete<v8::Task> >) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  25. 16: 0x1048bd064 node::PerIsolatePlatformData::FlushForegroundTasksInternal() [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  26. 17: 0x105051acc uv__async_io [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  27. 18: 0x105063d80 uv__io_poll [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  28. 19: 0x105051f74 uv_run [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  29. 20: 0x104898854 node::NodeMainInstance::Run() [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  30. 21: 0x10483514c node::Start(int, char**) [/Users/zhinushannan/.nvm/versions/node/v12.22.12/bin/node]
  31. 22: 0x1075c908c
  32. Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

其原因是Node在新款的 Mac 的 M1 macOS 系统运行的不是很好,可以通过安装已经修复的版本来运行,如14.17.1、15等。

Git

Mac自带git,不需要额外安装。
首先查看本地git是否已经配置,执行git config --global --list命令,如果没配置,则执行以下命令进行配置:

  1. git config --global user.name "github的用户名"
  2. git config --global user.email "github的邮箱"
  3. ssh-keygen -t rsa -C "github的邮箱" # 执行此条命令后需要连续按三次回车
  4. cat ~/.ssh/id_rsa.pub # 查看公钥

在GitHub的https://github.com/settings/keys中新建SSH KEY,将公钥复制进去,保存后,执行ssh -T git@github.com命令,若出现success字样,则说明配置成功!

Hadoop

首先去Hadoop官网下载需要版本的二进制包:官网(或者也可以去国内镜像下载:清华镜像)

3.Hadoop官网

下载完成后解压到指定目录,我设置的目录是~/environment,然后将hadoop的目录配置到~/.bash_profile中:

  1. export HADOOP_HOME=/Users/zhinushannan/environment/hadoop-3.3.3
  2. export HADOOP_INSTALL=$HADOOP_HOME
  3. export HADOOP_MAPRED_HOME=$HADOOP_HOME
  4. export HADOOP_COMMON_HOME=$HADOOP_HOME
  5. export HADOOP_HDFS_HOME=$HADOOP_HOME
  6. export YARN_HOME=$HADOOP_HOME
  7. export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
  8. export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"
  9. export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin

执行source ~/.bash_profile,执行hadoop命令检查是否可用。

Scala

进入Scala官网:官网
下载第二代版本的二进制包:

4.scala官网

5.scala二进制包

下载完成后解压到指定目录,我设置的目录是~/environment,然后将scala的目录配置到~/.bash_profile中:

PATH="/Users/zhinushannan/environment/scala-2.12.15/bin:${PATH}"

执行source ~/.bash_profile,执行scala命令检查是否可用。

Spark

进入Spark官网,根据安装的Hadoop版本选择Spark版本:官网

6.spark官网

下载完成后解压到指定目录,我设置的目录是~/environment,然后将scala的目录配置到~/.bash_profile中:

  1. export SPARK_HOME=/Users/zhinushannan/environment/spark-3.2.1-bin-hadoop3.2
  2. export PATH=$PATH:$SPARK_HOME/bin
  3. export PYSPARK_PYTHON=python39

其中python39是自己的python启动命令。

安装pyspark:pip39 install pyspark,执行source ~/.bash_profile,执行pyspark检查是否可用。

  1. Welcome to
  2. ____ __
  3. / __/__ ___ _____/ /__
  4. _\ \/ _ \/ _ `/ __/ '_/
  5. /__ / .__/\_,_/_/ /_/\_\ version 3.2.1
  6. /_/

Docker

前往官网下载:官网,下载完成后将dmg文件拖入Application进行安装,安装完成后点击Docker图标运行Docker。

7.docker

点击小鲸鱼图标,在Perferences中设置国内镜像:

8.docker镜像

  1. {
  2. "builder": {
  3. "gc": {
  4. "defaultKeepStorage": "20GB",
  5. "enabled": true
  6. }
  7. },
  8. "experimental": false,
  9. "features": {
  10. "buildkit": true
  11. },
  12. "registry-mirrors": [
  13. "http://hub-mirror.c.163.com",
  14. "https://docker.mirrors.ustc.edu.cn"
  15. ]
  16. }

点击Apply & Restart镜像源生效。

但是,此时是不能ping通Docker容器的,即无法与容器建立通信。如果有这个需求,需要做如下操作(提前安装好brew)。
安装docker-connector

  1. brew install wenjunxiao/brew/docker-connector
  2. ==> Downloading https://github.com/wenjunxiao/mac-docker-connector/releases/download/v3.1/docker-connector-darwin.tar.gz
  3. ==> Downloading from https://objects.githubusercontent.com/github-production-release-asset-2e65be/266031479/3f51cb4b-e37f-4f12-a492-5d057728562c?X-Amz-Algorithm=AWS4-HMAC-SHA25
  4. ######################################################################## 100.0%
  5. ==> Installing docker-connector from wenjunxiao/brew
  6. ==> Caveats
  7. For the first time, you can add all the bridge networks of docker to the routing table by the following command:
  8. docker network ls --filter driver=bridge --format "{{.ID}}" | xargs docker network inspect --format "route {{range .IPAM.Config}}{{.Subnet}}{{end}}" >> /opt/homebrew/etc/docker-connector.conf
  9. Or add the route of network you want to access to following config file at any time:
  10. /opt/homebrew/etc/docker-connector.conf
  11. Route format is `route subnet`, such as:
  12. route 172.17.0.0/16
  13. The route modification will take effect immediately without restarting the service.
  14. You can also expose you docker container to other by follow settings in /opt/homebrew/etc/docker-connector.conf:
  15. expose 0.0.0.0:2512
  16. route 172.17.0.0/16 expose
  17. Let the two subnets access each other through iptables:
  18. iptables 172.17.0.0+172.18.0.0
  19. To start wenjunxiao/brew/docker-connector now and restart at startup:
  20. sudo brew services start wenjunxiao/brew/docker-connector
  21. Or, if you don't want/need a background service you can just run:
  22. sudo docker-connector -config /opt/homebrew/etc/docker-connector.conf
  23. ==> Summary
  24. � /opt/homebrew/Cellar/docker-connector/3.1: 4 files, 5.3MB, built in 1 second
  25. ==> Running `brew cleanup docker-connector`...
  26. Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
  27. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

在日志中,可以看到docker-connector的配置文件在/opt/homebrew/etc/docker-connector.conf。确定自己电脑上的docker属于哪一个路由段(通常情况下是172.17.0.1),将对应的路由的注视去掉。

  1. # addr 192.168.251.1/24
  2. # mtu 1400
  3. # host 127.0.0.1
  4. # port 2511
  5. route 172.17.0.0/16
  6. # route 172.18.0.0/16
  7. # iptables 172.17.0.0+172.18.0.0
  8. # hosts /etc/hosts .local
  9. # proxy 127.0.0.1:80:80

启动docker-connector服务:

sudo brew services start docker-connector

运行docker前端容器:

docker run -it -d --restart always --net host --cap-add NET_ADMIN --name connector wenjunxiao/mac-docker-connector

此时就可以尝试与容器建立通信。

docker-connector官方:[https://github.com/wenjunxiao/mac-docker-connector](