0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

新しく環境構築&githubを使用する際の手順まとめ(pyenvも使用)

Last updated at Posted at 2025-05-22

環境構築する機会は度々あるのですが、いつも忘れた頃にやってくるので、個人用メモを含めて手順を記載します。
この記事の前提条件としては

  • AWSでの環境構築
  • pythonがすでにインストールされているが、別のバージョンのpythonを使いたい(=pyenvを使う)
  • bashにあまり詳しくないので、簡単めなことも書いています
    です。

pyenv

  • pyenvのインストール
curl https://pyenv.run | bash
  • .bashrcに追記(.bashrcファイルの末尾に書き加えられる)
    1行ずつ実行してもまとめてでもOK
    これをしないとpyenvが認識されない
echo '' >> ~/.bashrc
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
source ~/.bashrc
  • pythonのインストール
    例)pyenv install 3.10.12
pyenv install <pythonバージョン>
  • 仮想環境の作成
    例)pyenv install 3.10.12 myenv
pyenv virtualenv <pythonバージョン> <仮想環境名>
  • アクティベイト
pyenv activate <仮想環境名>
  • pythonライブラリのインストール
pip install <ライブラリ>

(参考)

github

  • public keyとprivate keyを.sshフォルダに作成

<もしssh keyを作成、githubに登録していない場合は実行↓>
適宜.sshがあるフォルダに移動します

cd ~/.ssh


public/private keyを作成

ssh-keygen

※こちらのサイトなどを参考に確認してください!
https://qiita.com/soma_sekimoto/items/35845495bc565c38ae9d

githubにkeyを登録

  • gitへ接続
    git clone...

  • コミット
    git add ファイル名, git commit

エラー①

私の場合git cloneしようとしたところなぜかssh: connect to host github.com port 22: Operation timed outエラーになってしまいました。色々調べたら、port:443を使うことで改善する可能性がある、とのことだったので、configファイルを作成しました。

  • ~/.ssh/configファイルの作成
Host github.com
    Hostname ssh.github.com
    Port 443
    User git
    IdentityFile <private keyのパス>

そうすると以下のような警告が表示されます

# The authenticity of host '[ssh.github.com]:443 ([140.82.112.36]:443)' can't be established.
# ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
# This host key is known by the following other names/addresses:
#     ~/.ssh/known_hosts:32: github.com
# Are you sure you want to continue connecting (yes/no/[fingerprint])?

githubの公式も安全と言っているのでyesと実行し先に進みましょう。
(参考)
https://docs.github.com/ja/authentication/troubleshooting-ssh/using-ssh-over-the-https-port

エラー②

鍵の設定の仕方が悪かったのか、私はさらにPermissions 0644 for {鍵の名前} are too open.というエラーになってしまいました。
なので以下のようにファイルの設定を変更します。

chmod 600 <private keyのパス>

(参考)
https://stackoverflow.com/questions/9270734/ssh-permissions-are-too-openzqz

そうしたらやっと接続することができました。

エラー③

git add ファイル名, git commitで進もうとしたところ、以下のエラーが返ってくることがある。

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"
to set your account's default identity.

これはgit config にユーザー情報が未登録な場合に出るため、アドレスとユーザー名を自分のものに置き換えてターミナルで実行する。

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

その後再度git commitするとpushできるようになる。

(参考)
https://qiita.com/C_HERO/items/c35e679f0b03a5f06469(--globalや--localの違いについて)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?