---
# System prepended metadata

title: Linux 環境架設
tags: [python, ' anaconda', ' mongodb']

---

---
tags: python, anaconda, mongodb
---

###### tags: [python](#Python), [anaconda](#Anaconda), [mongodb](#MongoDB)

# Linux 環境架設 


## Python
![](https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2F3.bp.blogspot.com%2F-nvYI29L9EWs%2FWyT2LaPF2lI%2FAAAAAAAAZ38%2FrXQwzgxBUjkEMihTPHtOwhL-nTnq5RsrQCEwYBhgL%2Fs1600%2FPythonWallpaper.jpg&f=1&nofb=1)
> Installation! [color=#26a69a]

### 1. 準備

```
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \ libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
```


### 2. 安裝

```
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz

sudo tar xzf Python-3.7.6.tgz
```


### 3. 編譯

>使用下面的命令集來使用altinstall在您的系統上編譯python原始碼

```
cd Python-3.7.6
sudo ./configure --enable-optimizations
sudo make altinstall
```
>安裝完成！


---


## Anaconda
![](https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.cloudera.com%2Fcontent%2Fdam%2Fwww%2FDownloads%2FProduct%2520Icons%2FxAnaconda_Logo_0702.png.pagespeed.ic.aLbBmyIA-u.png&f=1&nofb=1)
> Installation! [color=#26a69a]

### 1. 下載
```
wget https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh
```

### 2. 安裝
```
bash Anaconda3-2020.07-Linux-x86_64.sh 
```

### 3. PATH生效

```
source .bashrc
```

### 4. 創虛擬環境
```
conda create -n myenv python=3.7.6
```


### 5. 安裝所需套件

>使用下面的pip命令來安裝所需的套件

```
pip install -r requirements.txt
```


>完成！
---

## MongoDB
![](https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fanalyticstraining.com%2Fwp-content%2Fuploads%2F2016%2F08%2Fmongodb.jpeg&f=1&nofb=1)
> Installation! [color=#26a69a]

### 1. 匯入金鑰

```
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
```

### 2. 建立 /etc/apt/sources.list.d/mongodb-org-4.4.list

```
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
```

### 3. 更新套件庫

```
sudo apt-get update
```

### 4. 安裝 MongoDB

```
sudo apt-get install -y mongodb-org
```

### 5. 防止自動更新
```
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
```

### 6. 啟動MongoDB
```
sudo systemctl start mongod
```
> 若 ```systemctl start mongod``` 無法啟動[color=#26a69a]
```
sudo systemctl unmask mongod && sudo service mongod start
```

>完成！


