Post

从零配置 MacOS

News:Macworld我爱MAC

如何从 0 开始配置 MacBook Pro

Basic Configuration

打开 idle: idle3

pip install torchimport torch,虽然叫pytorch,但 conda install pytorch

Oh my zsh with autosuggestions & syntax-highlighting

MacOS安装Homebrew与Oh-My-Zsh

Install with curl

1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Enabling Plugins (zsh-autosuggestions & zsh-syntax-highlighting)

  • Download zsh-autosuggestions by

git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions

  • Download zsh-syntax-highlighting by

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

  • nano ~/.zshrc find plugins=(git)

  • Append zsh-autosuggestions & zsh-syntax-highlighting to plugins() like this

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

  • Reopen terminal

Ref

ubuntu py3.7安装jupyterhub

1
2
3
4
5
npm install -g configurable-http-proxy
sudo pip3 install jupyterhub
sudo conda install notebook
sudo pip3 install jupyterlab
jupyterhub --generate-config # 生成配置文件 

添加 c.ConfigurableHTTPProxy.command = '/usr/local/bin/configurable-http-proxy’jupyterhub_config.py

1
2
3
jupyterhub --port 1234 # 打开
# 远程要端口映射--把远端8888端口映射到本地8888端口--公钥被拒绝失败未解决
ssh -L8888:localhost:8888 root@ip04

macos jupyterhub error

Error: Nodename nor servname provided Solution: [https://github.com/jupyterhub/jupyterhub/issues/1586] –Workaround: –sudo jupyterhub --ip=localhost # jupyterhub –ip=0.0.0.0 and jupyterhub –ip=’’ result in the same error as above

Install Homebrew

IPAddress 上查看 raw.githubusercontent.comformulae.brew.sh 的IP,sudo vim /etc/hosts 新增:

1
2
185.199.109.133 raw.githubusercontent.com
185.199.108.153	formulae.brew.sh

运行官网安装命令 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)",不成功换用其他的IP尝试。

安装成功后,添加到系统路径:

1
2
3
echo >> /Users/yuy4o/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/yuy4o/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

更换 Homebrew 源为阿里云

替换brew.git:

1
2
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

替换homebrew-core.git:

1
2
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

替换homebrew-bottles:

1
2
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

切回官方源: 重置brew.git:

1
2
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

重置homebrew-core.git:

1
2
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

配置系统文件

1.open/vim /etc/profile(建议不修改这个文件)

全局(公有)配置,不管是哪个用户,登录时都会读取该文件

2./etc/bashr(一般在这个文件中添加系统级环境变量)

全局(公有)配置,bash shell执行时,不管是何种方式,都会读取此文件

3.-/.bash_profile(一般在这个文件中添加用户级环境变量)

(注:Linux 里面是 .bashrc 而 Mac是.bash_profile)

若bash shell 是以 login 方式执行时,才会读取此文件。该文件仅仅执行一次!默认情况下,设置一些环境变量

export PATH = $PATH: /Users/...export M2_HOME = /Users/... export PATH = $PATH:$M2_HOME/bin

查看端口占用,进程号,进程名

统计TCP/UDP端口号和对应服务,得到PID: echo "### TCP LISTEN ###" lsof -nP -iTCP -sTCP:LISTEN

杀死进程,释放端口: sudo kill -9 PID

Unix OS

IBM AIX:AIX只能在IBM Power System上运行——Power System是终端Unix服务器中性能最强大的

Oracle Solaris: Sun公司开发,后来Sun公司被Oracle并购。OpenSolaris免费开源

HP-UX:惠普

不同shell在终端里的显示

Shell是一个命令语言解释器(command-language interpreter),有内建的shell命令集,它是用户和Linux之间的接口程序。在提示符下输入的每个命令都由shell先解释然后传给Linux内核

Shell Change Command:

chsh -s path, path 是 /etc/shells 中列出的某个 Shell 路径,例如 /bin/zsh、/bin/bash、/bin/csh、/bin/dash、/bin/ksh、/bin/sh 或 /bin/tcsh

Bourne shell (sh):

1
IC-FVFJ3ADAQ6LR:~ yj522$  

Bourne Again shell (bash):

1
IC-FVFJ3ADAQ6LR:~ yj522$  

C shell (csh):

1
[IC-FVFJ3ADAQ6LR:~] yj522%

tcsh:

1
[IC-FVFJ3ADAQ6LR:~] yj522%

Korn shell (ksh):

1
$ 

Debian Almquist shell (dash):

1
$ 

The Z shell (zsh):

1
yj522@IC-FVFJ3ADAQ6LR ~ %

fish shell

让 zsh 模拟 sh: zsh --emulate sh

查看当前shell: echo $SHELLecho $0

查看安装的所有shell: cat /etc/shells

查看所有环境变量: export -p

配置文件路径格式:

export PATH="/Users/yj522/miniforge3/bin:$PATH"

export PATH=${PATH}:/Users/yj522/miniforge3/bin:/opt/homebrew/bin

1
2
PATH=${PATH}:/Users/yj522/miniforge3/bin:/opt/homebrew/bin
export PATH

1.${}为占位符,${PATH}$PATH等效 2. =前后不能有空格 3.: 为分隔符,等同于windows环境变量中的;

重载配置文件: source ~/.bash_profile. ~/.bash_profile

Bash的配置文件:

/etc/profile:为系统的每个用户设置环境信息,当用户第一次登录时会执行该文件里的命令。默认会直接调用/etc/bashrc。该文件的改动需要重启才能生效

/etc/bashrc:为每一个运行bash shell的用户执行此文件。当bash shell被打开时,会读取并执行该文件中的命令。所以修改该文件后,重新打开Shell即可生效

~/.bash_profile:和/etc/profile类似,但是只对当前用户生效

~/.bashrc:和/etc/bashrc类似,但是只对当前用户生效

~/.bash_logout:当每次退出bash shell时,执行该文件

~/.bash_history:保存了历史命令。在Shell为Bash时,每次敲击命令时,都会保存在这个文件里

Zsh的配置文件:

.zshenv:存放的环境变量配置项在任何场景下都能被读取,这里通常把$PATH等变量写在这里,这样无论是在交互shell,或者运行程序都会读取此文件。个人理解对标Bash的profile

.zshrc:在交互式shell中会读取并执行该文件,包含设置别名、函数、选项、键绑定等命令。对标bashrc

.zlogin:在login shell的时候读取

.zprofile:和.zlogin类似,但是是在.zshrc之前加载

.zlogout:退出终端的时候读取,用于做一些清理工作。对标bash_logout

.zsh_history:保存了历史命令。在Shell为Zsh时,每次敲击命令时,都会保存在这个文件里

加载顺序:zshenv、zprofile、zshrc、zlogin 来源

环境变量配置

通过 echo $SHELL 查看shell类型后向配置文件 ~/.zshrc~/.bashrc~/.bash_profile等中添加环境变量

1
2
3
4
echo 'export PATH="/opt/myapp/bin:$PATH"' >> ~/.bashrc #在$PATH前添加路径,高优先级
echo 'export PATH="$PATH:/opt/myapp/bin"' >> ~/.bashrc #在$PATH后添加路径,低优先级
echo 'export MY_APP_HOME="/opt/myapp"' >> ~/.bashrc # 路径包含空格需要加引号
echo 'export MY_APP_HOME=/opt/myapp' >> ~/.bashrc # 路径无空格引号可省略

MacOS 磁盘空间清理

备份文件 ~/资源库/Application Support/MobileSync/Backup/

临时文件 ~/资源库/Caches/

MacOS Software

BetterSnapTool/ Magnet

xsnip, haze over

Emacs

Navicat Premium, phpstudy_pro 数据库

electerm, hyper 终端

OmniGraffle 流程图

Hyper 终端,js配置

Effie 写作

IINA 宇宙最强开源播放器,VLC老了,免费而且极其高效,占用低,解码速度快,支持多种格式

Downie 下载YouTube视频

tampermonkey Chrome 配合JavaScript插件,基本上也可以做任何事情了

RayLink 远程控制

X

必装

AlDente, BetterDisplay, Bartender 4, Caffeine, iStat Menus, RunCat, Tot, NeatReader, iRightMouse Lite, Shadowrocket/ClashX, Alfred 5, LyricsX, Screen Recorder by Omi, iShot, cleanMyMac X, Parallels Desktop

推荐

sogou, Dropover, Rectangle, Effie, Blackmagic Disk Speed Test, Typora, iTerm2, tmux, postman, microsoft remote desktop, neofetch, Freeform

LaTex

online: overleafTeXPage

TeX Live-MacTeX + LaTeX Workshop 视频教程

Qt Creater

1.分别安装qt和qt creator

2.https://mirrors.aliyun.com/qt/ 选official_releases/ 而非 archive/

3.qt creator6之后是新版

Sublime Text

Emacs

VSCode

调试C++代码时配置json文件

Pycharm

从命令行打开 Pycharm:

1
2
3
vim ~/.zshrc
alias pycharm = "open -a pycharm"
source ~/.zshrc

Typora

massCode

Xtranslator

WPS Office

OBS配置视频

VMware

Workstation 和 Fusion 对个人使用完全免费,企业许可转向订阅

VMware Fusion 13 for Mac

Parallels Desktop

Apple芯片Mac安装ARM版Win10完美教程

Shotcut & Command

MacBook:

space:预览

cmd + tab:应用间切换

cmd + W:关闭当前窗口

cmd + Q:退出应用

cmd + M:窗口最小化

cmd + O:打开文件夹

cmd + 上/下:上下级目录切换

cmd + I:打开文件信息

cmd + del:删除文件

cmd + /:显示选中文件数及剩余空间

cmd + shift + .:显示隐藏文件

cmd + 拖动窗口:被拖动窗口置于底层

任意目录下拼写目标文件(夹)首词,快速跳转,类似查找功能

vscode:

cmd+k+z:专注模式

终端:

open -a 应用名:打开应用

ps:观察正在执行的shell

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.