新机配置(mac)

# 新机配置(mac)

# 1.注册APPID

开机,按照提示步骤操作即可。

# 安装工具

# 常用工具

  • 浏览器:谷歌浏览器、Safari(mac自带)、Firefox

设置搜索引擎为百度,安装扩展程序(FeHelper (opens new window)、)chrome导入书签 (opens new window)

  • 笔记:有道云笔记、xmind
  • 网盘:百度云网盘
  • 会议:Team Viewer、腾讯会议
  • 词典:网易有道云词典
  • photo shop

百度云网盘中的三个下载包下载,解压,断网,安装,用TNT破解,重新打开即可

# 工作涉及

# 配置开发环境

  • 安装xcode命令行开发工具

首先打开终端,输入:xcode-select --install;出现弹框,点击安装

如果安装提示网络问题参照此链接 (opens new window)手动安装;Mac安装Xcode (opens new window)Developer Apple (opens new window)

# 显示当前Xcode版本,如果已安装,会出现如下提示
xcode-select --version 
xcode-select version 2354.

# 如果未安装,可通过下方命令安装;如果已安装会出现下面提示
xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

# 查看当前xcode的版本目录
xcode-select -p
/Library/Developer/CommandLineTools

# 查看版本信息
gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  • 安装Homebrew

Homebrew是一款Mac OS平台下的软件包管理工具;安装 Apple(或您的 Linux 系统)没有预装但你需要的东西。

流程:

  1. 参照官网 (opens new window)进行安装;然后enter,输入密码,等待...
  2. 安装完成后输入:brew --version,出现版本号即表示安装成功;
  3. 接着安装wget、curl、git;一般mac终端默认已安装curl、git;输入:git --verison/curl --version出现版本号即可验证;若无则安装;以wget为例:brew install wget;安装成功,输入:wget --version即可验证是否安装成功
# 查看配置
brew config 
HOMEBREW_VERSION: 2.2.16
ORIGIN: https://github.com/Homebrew/brew
HEAD: c0f5a52d85d3606e7600162a9d38936ab4b46f4f
Last commit: 1 year, 10 months ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: d7102825baf8116da0e12de7155427f6626cb700
Core tap last commit: 1 year, 10 months ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_MAKE_JOBS: 8
CPU: octa-core 64-bit kabylake
Homebrew Ruby: 2.6.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3/bin/ruby
Clang: 10.0 build 1001
Git: 2.20.1 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.54.0 => /usr/bin/curl
macOS: 10.14.1-x86_64
CLT: 10.3.0.0.1.1562985497
Xcode: N/A
  • 安装iTerm2 + oh-my-zsh

下载iTerm2,下载链接见终端工具

流程:

  1. 首先打开终端,输入:echo $SHELL;查看当前shell;一般mac默认为bash;
  2. 输入:cat /etc/shells;查看支持的shell列表;查看是否含有/bin/zsh;输入zsh --version;查看zsh版本号;
  3. 输入:chsh -s /bin/zsh;输入密码,切换到zsh;切换之后要重新打开终端,输入:echo $SHELL;验证是否切换成功;
  4. 安装oh-my-zsh,参照上方官网
  5. 安装zsh插件:brew install autojump
  • 安装node + npm

参照官网 (opens new window)下载node.js安装包

流程:

  1. 安装,一路同意....,安装成功后在终端输入:node --version;出来版本号即安装成功
  2. 安装node的同时也安装了npm,输入:npm --version即可见版本号
  3. 这时我们试着用npm安装一个插件看看能否安装成功;或者输入:npm install -g npm 更新npm 版本;
  4. 如果更新失败,报错:npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules,是因为默认的安装位置是/usr/local/lib所在的文件夹,这是系统的文件夹所在地,所以可能会出现一些读写问题。将module的安装根目录设置在一般的文件夹下则没有这么多问题;解决方法 (opens new window)如下:
# 第一步:在你的用户文件下新建一个文件夹,这个.npm-global 名字可以用你自己喜欢的名字替换,推荐直接使用这个名字。
mkdir ~/.npm-global
#第二步:更改node的安装连接
npm config set prefix '~/.npm-global'
#第三步:在用户的profile下增加path,为的是系统能够找到可执行文件的目录
 export PATH=~/.npm-global/bin:$PATH
#第四步:update profile。使其生效
source ~/.profile

重新npm install -g npm;即更新npm版本成功

使用cnpm来安装的方便在于比npm安装速度更快(相对国内而言),淘宝镜像cnpm在国内可以代替npm安装其可以安装的插件等。

根据官网介绍安装:npm install -g cnpm -registry=https://registry.npm.taobao.org

Yarn是由Facebook、Google、Exponent 和 Tilde 联合推出了一个新的 JS 包管理工具 ,是为了弥补 npm 的一些缺陷而出现的。 brew install yarn;安装完成后按照提示修改path

  • 安装nvm

nvm 是 Tim Caswell 开发的一款 Mac 系统中使用的通过命令方式管理多版本 Node.js 的软件。

github地址 (opens new window) 安装说明 (opens new window)

  • 安装pnpm

PNpm (opens new window)

npm install -g pnpm

  • 配置git环境

    • git -version 查看git是否安装,否则brew install git或者通过官网安装;
    • 配置用户名和用户邮箱,以后每次与Git的交互都会使用该信息。
    git config --global user.name "your_name"  
    git config --global user.email "your_email@gmail.com"
    
    • Git关联远端仓库时候需要提供公钥,本地保存私钥,每次与远端仓库交互时候,远端仓库会用公钥来验证交互者身份。使用以下指令生成密钥:
    ssh-keygen -t rsa -C "your_email@youremail.com" # 输入之后一路回车
    
    • 生成密钥后,在本地的/Users/当前电脑用户/.ssh目录下会生成两个文件id_rsa、id_rsa.pub,id_rsa文件保存的是私钥,保存于本地,id_rsa.pub文件保存的是公钥,需要将里面内容上传到远端仓库
    cat ~/.ssh/id_rsa.pub # 复制内容,粘贴到github账号的SSH keys中
    
    • 配置密钥成功,就可以clone项目了

    参考 (opens new window)

# VSCode配置

  • 设置中文

command+shift+p;输入config,选择language,点击其他语言选项,安装中文简体扩展包,按照提示操作即可。 参考 (opens new window)

  • eslint配置

code ==> 首选项 ===> 设置 ===> serting.json 中添加配置;参考 (opens new window)

{
  // 系统配置
  "window.zoomLevel": -1, // 缩放比例
  "editor.fontSize": 16, // 字体大小
  "editor.tabSize": 4, // tab 空格数
  "breadcrumbs.enabled": false,
  "git.path": "D:\\Program Files (x86)\\Git\\bin\\git.exe",
  "terminal.integrated.shell.windows": "D:\\Program Files (x86)\\Git\\bin\\bash.exe",
  "workbench.iconTheme": "Monokai Pro (Filter Spectrum) Icons",
  // "gitlens.hovers.currentLine.over": "line",
  // "gitlens.currentLine.enabled": false,
  // "gitlens.hovers.enabled": false,
  // "gitlens.codeLens.enabled": false,
  "workbench.statusBar.visible": true,
  "window.menuBarVisibility": "default",
  // eslint配置
  "eslint.run": "onSave", // 保存的时候执行校验
  // eslint 自动修复
  "eslint.autoFixOnSave": true, // 默认只支持.js
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "eslint.validate": [ // eslint校验
    "javascript",
    "javascriptreact",
    "html",
    {
      "language": "html", // 检测.html
      "autoFix": true
    },
    {
      "language": "vue", // 检测.vue
      "autoFix": true
    },
    {
      "language": "typescript", // 检测.ts
      "autoFix": true
    },
  ],
  "eslint.options": {
    "plugins": [
      "html"
    ]
  },
  "eslint.trace.server": "messages",
  "javascript.suggest.autoImports": false,
  "javascript.updateImportsOnFileMove.enabled": "never",
  "typescript.preferences.importModuleSpecifier": "non-relative",
  "typescript.updateImportsOnFileMove.enabled": "never",
  "typescript.suggest.autoImports": false,
  // Pritter
  "prettier.tabWidth": 4,
  "prettier.singleQuote": true,
  "files.autoSave": "onFocusChange",
  "workbench.startupEditor": "newUntitledFile",
  "editor.minimap.enabled": true,
  "editor.renderWhitespace": "none",
  "editor.renderControlCharacters": false,
  "terminal.integrated.experimentalUseTitleEvent": true,
  "window.openFoldersInNewWindow": "on",
  "editor.wordWrap": "on",
  "editor.dragAndDrop": false,
  "terminal.integrated.splitCwd": "initial",
  "stylusSupremacy.insertColons": true, // 是否插入冒号
  "stylusSupremacy.insertSemicolons": false, // 是否插入分好
  "stylusSupremacy.insertBraces": false, // 是否插入大括号
  "stylusSupremacy.insertNewLineAroundImports": false, // import之后是否换行
  "stylusSupremacy.insertNewLineAroundBlocks": false,
  "gitlens.advanced.messages": {
    "suppressFileNotUnderSourceControlWarning": true
  },
  "gitlens.gitCommands.closeOnFocusOut": true,
  "[vue]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  } // 两个选择器中是否换行
}
  • 配置Code命令

参考 (opens new window)

报错:EACCES: permission denied, unlink '/usr/local/bin/code'

参考 (opens new window)

  • 配置·vue模板

参考 (opens new window)

Code Helper占用大量CPU和内存 (opens new window)

  • 扩展工具
GitLens   # git提交记录
Chinese (Simplified) Language Pack for Visual Studio Code  # 中文语言包
ESLint # 代码规范
HTML Snippets   # 自动帮你输入HTML标签
Image preview    # 图片资源预览
Debugger for Chrome    # 在vs中启动chrome控制台
小程序助手、Live HTML Previewer、open in browser、SVG viewer、View in Browser、VS Color Picker、vscode-icons、Vetur、Live Server
any-rule(正则大全)

# 常见问题

  1. 安装 homebrew 报错
mac@localhost ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

解决办法:使用国内源:/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" 该地址提供多个国内源地址,安装非常简便,亲测有效。 查检安装结果:brew -v, 如果能正确打印版本信息,则安装成功!参考 (opens new window)

  1. npm install -g npm 报错: npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/npm' -> '/usr/local/lib/node_modules/.npm-i9nnxROI'
# 权限问题,sudo一下
sudo npm install -g npm
# 输入密码即可~

问题:如何配置免密下载?

  1. brew install wget报错:
mac@localhost .ssh % brew install wget
Error: The following directories are not writable by your user:
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1

And make sure that your user has write permission.
  chmod u+w /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1

解决办法:按提示操作即可~参考 (opens new window)

sudo chown -R $(whoami) /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1
chmod u+w /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1
brew install wget
  1. ohmyzsh下载被443拒绝连接: Failed to connect to raw.githubusercontent.com port 443: Connection refused

使用国内的项目地址下载,参考 (opens new window)

sh -c "$(wget -O- https://gitee.com/shmhlsy/oh-my-zsh-install.sh/raw/master/install.sh)"
上次更新: 11/30/2024, 10:08:28 PM
最近更新
01
taro开发实操笔记
09-29
02
前端跨端技术调研报告
07-28
03
Flutter学习笔记
07-15
更多文章>