Preface#
Using a
Linuxdevelopment environment onMac OSis not difficult, asMac OSitself is aUnix-likesystem, and withHomeBrew, mostLinuxsoftware packages can be installed directly. Even without using a virtual machine, you can have a relatively good development experience. However, there may be special requirements, or you might not want to pollute the host machine's development environment. In that case, you can use tools likeVMware Fusion,Parallels Desktop, orVirtualBoxto install a complete Linux distribution in a virtual machine. However, these types of virtual machines are relativelyheavy, slow to start, and consume a lot of memory, so they are not within my consideration. Of course, you can also useDocker Desktopto directly use variousLinuxdistribution images or create aDev Containerto create a fully equipped development image. However, currently, there is no one-size-fits-all solution for the issues withDockerimage sources, so that is also not in my consideration. Ultimately, I decided to useMechinesinOrbstackto set up a development environment.
Installing Orbstack#
You can directly download the installation package from the official website, or install it directly using HomeBrew.
brew install orbstack
Choosing a Suitable Distribution#
I am using Fedora here.


Perfecting the Development Environment#
- The first step is to change to the
Tsinghua source. First, back up the default source. 
sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.backup
Then directly replace the default source.
sudo sed -e 's|^metalink=|#metalink=|g' \
  -e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora|g' \
  -i.bak \
  /etc/yum.repos.d/fedora.repo \
  /etc/yum.repos.d/fedora-modular.repo \
  /etc/yum.repos.d/fedora-updates.repo \
  /etc/yum.repos.d/fedora-updates-modular.repo
If you prefer to change it manually:
- 
Fedora repository (/etc/yum.repos.d/fedora.repo)
[fedora] name=Fedora $releasever - $basearch failovermethod=priority baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/releases/$releasever/Everything/$basearch/os/ metadata_expire=28d gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch skip_if_unavailable=False - 
Updates repository (/etc/yum.repos.d/fedora-updates.repo)
 
[updates]
name=Fedora $releasever - $basearch - Updates
failovermethod=priority
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/updates/$releasever/Everything/$basearch/
enabled=1
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False
- 
Fedora-modular repository (/etc/yum.repos.d/fedora-modular.repo)
[fedora-modular] name=Fedora Modular $releasever - $basearch failovermethod=priority baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/releases/$releasever/Modular/$basearch/os/ enabled=1 metadata_expire=7d gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch skip_if_unavailable=False - 
Updates-modular repository (/etc/yum.repos.d/fedora-updates-modular.repo)
 
[updates-modular]
name=Fedora Modular $releasever - $basearch - Updates
failovermethod=priority
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/updates/$releasever/Modular/$basearch/
enabled=1
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False
```
- 
Clean the cache.
sudo dnf clean all sudo dnf makecache - 
Update the packages.
sudo dnf update 
- Replace the default 
bashwithzsh. 
- Install 
gitandzsh. 
sudo dnf install git zsh
- Install 
oh my zsh. 
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
- 
Install commonly used
oh my zshplugins.- Auto-suggestions.
 
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions- Syntax highlighting.
 
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting 
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting
```
- Auto-completion.
```bash
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git $ZSH_CUSTOM/plugins/zsh-autocomplete
```
- 
Modify the
zshconfiguration file to change the plugins to:vim ~/.zshrcplugins=( git zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting zsh-autocomplete 
)
- Apply the changes.
```bash
source ~/.zshrc
- Install 
NVMto manageNodeJSversions. 
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
- 
How to use:
$ nvm use 16 Now using node v16.9.1 (npm v7.21.1) $ node -v v16.9.1 $ nvm use 14 Now using node v14.18.0 (npm v6.14.15) $ node -v v14.18.0 $ nvm install 12 Now using node v12.22.6 (npm v6.14.5) $ node -v v12.22.6For advanced usage, please refer to the documentation.
 
- Use 
VS Codeto connect to the virtual machine you just created. 
- Install the 
Remote Developmentextension. - Add a remote connection. In the left menu, select Remote Explorer, click the 
+sign onSSH, or use the shortcutShift+Command+Pand typeremote addto open the window for addingSSHconnections.

Enterssh orbto connect to the virtual machine you just created.
::: warning
If you have multiple virtual machines, you need to specify which host to connect to when usingSSH. If not specified, it will connect to the default host. For example,ssh debain@orbconnects to thedebainhost with the default user. Examples include
ssh machine@orb,
ssh user@orb,
ssh user@machine@orb.
:::


 
This way, you have a development environment isolated from the host system. No matter how much you tinker, you don't have to worry, somewhat similar to
WSLinWindows, but simpler and more convenient, without needing to enable certain features of the system. You can use it directly after downloadingOrbstack.
This article is synchronized and updated to xLog by Mix Space. The original link is https://remrin.dev/posts/linux/dev-env