开发环境配置
最后更新于:2022-04-02 05:45:06
[TOC]
# GIthub 上的项目
https://github.com/donnemartin/dev-setup
创建一个新的开发人员机器可以是一个特别的、手动的、耗时的过程。devsetup的目的是简化过程,使用易于理解的指令和多文件/脚本实现以下步骤的自动化:
OS X updates and Xcode Command Line Tools
OS X defaults geared towards developers
Developer tools:Vim, bash, tab completion, curl, git, GNU core utils, Python, Ruby, etc
Developer apps: iTerm2, Sublime Text, Atom, VirtualBox, Vagrant, Docker, Chrome, etc
Python data analysis: IPython Notebook, NumPy, Pandas, Scikit-Learn, Matplotlib, etc
Big Data platforms:Spark (with IPython Notebook integration) and MapReduce
Cloud services: Amazon Web Services (Boto, AWS CLI, S3cmd, etc) and Heroku
Common data stores: MySQL, PostgreSQL, MongoDB, Redis, and Elasticsearch
Javascript web development:Node.js, JSHint, and Less
Android development: Java, Android SDK, Android Studio, IntelliJ IDEA
# Xcode 安装管理
https://github.com/KrauseFx/xcode-install
# Android 开发环境
## android-platform-tools
1. Install adb
~~~
brew install android-platform-tools
~~~
2. Start using adb
~~~
adb devices
~~~
## Android-SDK-Manager
http://developer.android.com/sdk/index.html#mac-tools
参考:https://stackoverflow.com/questions/31374085/installing-adb-on-macos
给二个靠谱的网址:
1. http://www.androiddevtools.cn/index.html
2. http://down.tech.sina.com.cn/page/45703.html
3. http://mac.softpedia.com/get/Developer-Tools/Google-Android-SDK.shtml
到这个面下载后,解压到某个目录。
或者通过`brew install android-sdk` 安装~,我好像安装之后,调不出 sdk manager~,在以后研究。
[如何在mac本上安装android sdk](https://www.cnblogs.com/yjmyzz/p/4219829.html)
# Node Version Manager
官网:https://github.com/creationix/nvm
## 安装 nvm
~~~
brew install nvm
~~~
然后重启终端。
### nvm command not found!
~~~
mkdir ~/.nvm
export NVM_DIR="$HOME/.nvm"
. "/usr/local/opt/nvm/nvm.sh"
~~~
## 使用方法
1. 安装 指定node版本
~~~
nvm install node #默认安装最新版本。
nvm install 8.9.4 #命令后加版本号就可以进行安装,字母v可以不写
~~~
2. 查看当前使用的版本
~~~
nvm current
~~~
3. 切换指定版本,切换效果是全局的
~~~
nvm use v7.9.0
~~~
4. 查看该系统已经安装的版本,这个命令也能看到当前使用的是哪个版本
~~~
nvm ls
~~~
## 国内 npm 加速
[nrm](https://github.com/Pana/nrm) 是管理npm源切换的利器,简单方便。
~~~
npm i nrm -g #安装 nrm
nrm test #测试源的响应时间,可以作为使用哪个源的参考
nrm use cnpm # 使用 cnpm
nrm ls #查看状态
~~~
# jEnv
[jenv](https://github.com/gcuisinier/jenv#readme) 是一个专门用于配置 `JAVA_HOME` 环境变量工具(用来设置 `JAVA_HOME` 环境变量的)。你可以用它来管理 Mac 上的 Java 版本。
查看本机当前 已安装 java 版本
~~~shell
/usr/libexec/java_home -V
/usr/libexec/java_home -v 1.8
~~~
## 安装 jenv
~~~shell
brew install jenv
# 或者
git clone https://hub.fastgit.org/gcuisinier/jenv.git ~/.jenv
~~~
## 配置 jenv
Bash
~~~
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(jenv init -)"' >> ~/.bash_profile
~~~
Zsh
~~~
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(jenv init -)"' >> ~/.zshrc
~~~
如果已经添加但是仍没有生效的话,可以试一下重新加载bash_profile
~~~
source ~/.bash_profile
~~~
## 安装 JDK
Apple 已[发布公告](https://developer.apple.com/library/prerelease/mac/releasenotes/General/rn-osx-10.11/index.html),声明 Mac OS X 10.11 (El Capitan) 将为最后一个支持 Java 6 的 OS X 发行版。
现在 OS X 都不会自带 JDK 了,所以 需要 Oracle 网站上下载。
1. 手动下载: [JAVA SDK](http://www.oracle.com/technetwork/java/javase/overview/index.html)
2. brew 安装 java
```shell
brew tap AdoptOpenJDK/openjdk
# 下载 Jdk8
brew install --cask homebrew/cask-versions/adoptopenjdk8
# 或者 jdk15
brew cask install adoptopenjdk15
```
**Mac 的 Java 默认会安装到 `/Library/Java/JavaVirtualMachines/` 路径下**。
接着配置 JAVA 多版本:
> ⚠️具体 jdk 目录,可以切到 `/Library/Java/JavaVirtualMachines/` 下查看!
~~~
# 成功添加 jdk1.8 配置到 jEnv
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/
oracle64-1.8.0.131 added
1.8.0.131 added
1.8 added
# 添加 jdk9
$ jenv add /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home
$ jenv default java 1.8
~~~
成功之后,运行 `echo $JAVA_HOME`,如果定位到了`/Users/chandlerver5/.jenv/candidates/java/current`,说明配置成功。
## 列出管理的JDK
~~~
$ jenv versions
* system (set by /Users/demo/.jenv/version)
1.7
1.7.0.45
1.8
1.8.0.131
oracle64-1.7.0.45
oracle64-1.8.0.131
~~~
看起来有点多,但其实就是1.7、1.8两个版本的别名。
## 使用Java版本
配置全局Java版本
~~~
$ jenv global 1.7
~~~
配置当前目录的 Java 版本
~~~
$ jenv local 1.8
~~~
这种方式会只改变当前所在目录的 jdk 版本,可以通过如下命令取消
~~~
$ jenv local --unset
~~~
配置 shell 实例的版本
~~~
jenv shell 1.8
~~~
这种配置方式,只会影响当前 shell 窗口。
## 配置JVM Options
~~~
$ jenv global-options "-Xmx512m"
~~~
or
~~~
$ jenv local-options "-Xmx512m"
~~~
or
~~~
$ jenv shell-options "-Xmx512m"
~~~
# 卸载JDK
~~~
sudo rm -fr ~/Library/Application\ Support/Java
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk.jdk
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefpane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf /Library/LaunchAgents/com.oracle.java.Java-Updater.plist
sudo rm -rf /Library/PrivilegedHelperTools/com.oracle.java.JavaUpdateHelper
sudo rm -rf /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist
sudo rm -rf /Library/Preferences/com.oracle.java.Helper-Tool.plist
~~~
## 系统自带切换
[mac中不同jdk版本切换](https://www.jianshu.com/p/91bbb537fd52)
# ~~jenv (他们网站关闭了)~~
(请注意该工具不同于 jEnv, 这是用来设置 `JAVA_HOME` 环境变量的,不但支持 管理Java 多版本,还支持其他Java开发工具!)
[jenv](https://github.com/linux-china/jenv) 支持 Windows、Mac 和 Linux – 可以轻松管理大量**基于 Java 开发的工具**的多个版本,如 Maven、Gradle 或者是 Tomcat 之类。目前已经支持超过 200 个不同的工具。
安装 jenv:
~~~
$ curl -L -s get.jenv.mvnsearch.org | bash
~~~
接着配置 JAVA 多版本:
> ⚠️具体 jdk 目录,可以切到 `/Library/Java/JavaVirtualMachines/` 下查看!
~~~
$ mkdir -p $HOME/.jenv/candidates/java
$ ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home $HOME/.jenv/candidates/java/1.8
$ ln -s /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home $HOME/.jenv/candidates/java/9.0
$ jenv default java 1.8
~~~
查看jenv 支持的多个工具:
~~~
$ jenv all
~~~
例如 查看 `java` ,运行:
~~~
$ jenv list java
~~~
如果你想 安装 其中的 java 一个版本,会提示你去官网下载!
~~~
$ jenv install java 1.8.0_77
Please visit http://www.oracle.com/technetwork/java/javase/downloads/ and download dmg file.
~~~
安装其他的可以,也支持管理本地的已经安装的工具,或是github上的源。
~~~
$ jenv list maven
$ jenv install maven 3.3.9
~~~
安装成功之后,`mvn --version` 检查安装成功。
更新jenv
~~~
$ jenv selfupdate
~~~
> [使用 Jenv 让所有 Java 开发工具同时运行多个版本](https://coyee.com/article/12114-how-to-run-multiple-versions-of-all-your-dev-tools-with-jenv)
# MySql
1. 安装:搜索 mysql 版本 brew search mysql (若不更具需要选择,会默认最新版本)
~~~
$ brew install mysql
~~~
安装成功后:
~~~
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/mysql/bin:$PATH"' >> ~/.zshrc
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Summary
🍺 /usr/local/Cellar/mysql/8.0.12: 255 files, 233.0MB
~~~
查看 mysql 信息:
~~~
brew info mysql
~~~
2. 创建my.cnf配置文件
mysql 在新版中去掉了默认配置文件my.cnf如果需要可以手动创建。
首先需要知道系统是按如下顺序去找my.cnf:
~~~
i. /etc/my.cnf
ii. /etc/mysql@5.7/my.cnf
iii. /usr/local/etc/my.cnf
iv. ~/.my.cnf
~~~
所以就在 `/etc`下创建 `my.cnf`
~~~
$ sudo vim /etc/my.cnf
~~~
配置文件内容如下:
~~~
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
default-character-set=utf8
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
character-set-server=utf8
init_connect='SET NAMES utf8
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
character-set-server=utf8
init_connect='SET NAMES utf8'
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,
# MASTER_USER=, MASTER_PASSWORD= ;
#
# where you replace , , by quoted strings and
# by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host =
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user =
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port =
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
default-character-set=utf8
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
~~~
3. 加入launchctl启动控制
~~~
$ mkdir -p ~/Library/LaunchAgents
$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
$ find /usr/local/Cellar/mysql/ -name "homebrew.mxcl.mysql.plist" -exec cp {} ~/Library/LaunchAgents/ \;
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
# 取消启动
# launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
~~~
4. 初始化 mysql
~~~
mysql_install_db
~~~
5. 需要先启动 mysql ,执行安全设置脚本,设置root账号密码
~~~
mysql_secure_installation
~~~
6. 最后测试一下登陆
~~~
$ mysql -u root -p
~~~
# Python
# nginx
# tomcat
~~~
$ brew install tomcat
~~~
安装成功后:
~~~
==> Caveats
To have launchd start tomcat now and restart at login:
brew services start tomcat
Or, if you don't want/need a background service you can just run:
catalina run
==> Summary
🍺 /usr/local/Cellar/tomcat/9.0.10: 626 files, 13.3MB, built in 11 seconds
~~~
检查是否安装成功:
~~~
$ catalina -h
~~~
运行tomcat:
~~~
$ catalina run
~~~
正常是可以成功的了,访问`http://localhost:8080` 看下是否出现Tomcat的网站。
webapp的根目录(CATALINA_HOME)为:`/usr/local/Cellar/tomcat/9.0.10/libexec/webapps/ROOT/`
# Tomcat
catalina 就是Tomcat服务器使用的 Apache实现的servlet容器的 名字。
Tomcat的核心分为3个部分:
(1)Web容器---处理静态页面;
(2)catalina --- 一个servlet容器-----处理servlet;
(3)还有就是JSP容器,它就是把jsp页面翻译成一般的servlet。
catalina脚本启动参数
~~~
-help : 输出命令行选项的摘要表
-nonaming : 在tomcat中停用JNDI
-security : 启用catalina.policy文件
debug : 以调试模式启动tomcat
embedded : 在嵌入模式中测试tomcat;应用程序服务器的开发者通常使用此选项
jpda start : jpda 的调试方式启动tomcat
run : 启动tomcat,但不会重定向标准输出与错误
start : 启动tomcat,并将标准输出与错误送至tomcat的日志文件
stop : 停止tomcat
version : 输出tomcat的版本信息
~~~
https://www.jb51.net/article/120665.htm
https://blog.csdn.net/wild46cat/article/details/52412330
# [rbenv](https://github.com/sstephenson/rbenv)
人人都需要一个 Ruby 版本管理工具。rbenv 就是这样一个轻量级工具,它可以通过 brew 安装。
安装:
~~~
brew install rbenv ruby-build
~~~
然后在`~/.zshrc`中加上rbenv插件。否则你需要手动添加`eval "$(rbenv init -)"`到`~/zshrc`或者`~/.zprofile`文件里。
有时候项目会依赖一些奇怪的版本号,比如ruby-2.1.0,这个时候你需要 [rbenv-aliases](https://github.com/tpope/rbenv-aliases) 帮忙:
~~~
brew install rbenv-aliases
~~~
替代品有 RVM、chruby。因为 RVM 不能通过 brew 安装,并且安装的时候会没有节操的修改一堆文件,所以被我早早的弃用了。chruby 也是一个轻量级工具,而且可以完美的和 Oh My Zsh 集成在一起,我看到有些生产环境在用它。
## Ruby 常用别名
几乎所有 Ruby 开发人员都会把`bi`作为bundle install的别名。
Oh My Zsh 提供builder插件,这个插件提供了一套别名,比如`bi`、`be`。同时还能让你在运行一些常用 gem 的时候直接输入`rspec`,不需要`be rspec`这样了。具体包括哪些命令请[参考这里](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/bundler)。
Z shell 对于`[`和`]`符号有特殊的处理,所以在运行`rake task[parameter]`的时候会报错,你需要改成`rake task\[parameter\]`或者`noglob rake task[parameter]`。
然而 Oh My Zsh 已经看穿这一切,自带的 rake 插件已经解决了这个问题:`brake task[parameter]`。
添加插件的时候注意把`rake`放到`bundler`后面,例如这样:
~~~
plugins=(git z sublime history rbenv bundler rake)
~~~
';