1
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?

More than 1 year has passed since last update.

wslでelixir その48

Last updated at Posted at 2023-09-07

概要

wsl(wsl2じゃない)で、elixirやってみた。
Phoenix、やってみた。

インストール

$ mix local.hex
Are you sure you want to install "https://repo.hex.pm/installs/1.13.0/hex-2.0.6.ez"? [Yn] y
* creating /home/ore/.mix/archives/hex-2.0.6

$ mix archive
* hex-2.0.6
Archives installed at: /home/ore/.mix/archives

$ sudo apt-get install postgresql
$ sudo service postgresql start
$ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"

$ mix archive.install hex phx_new
Resolving Hex dependencies...
Resolution completed in 0.048s
New:
	phx_new 1.7.7
* Getting phx_new (Hex package)
All dependencies are up to date
** (Mix) You're trying to run :phx_new on Elixir v1.13.4 but it has declared in its mix.exs file it supports only Elixir ~> 1.14

$ mix archive.install hex phx_new 1.6.15
Resolving Hex dependencies...
Resolution completed in 0.043s
New:
	phx_new 1.6.15
* Getting phx_new (Hex package)
All dependencies are up to date
Compiling 11 files (.ex)
Generated phx_new app
Generated archive "phx_new-1.6.15.ez" with MIX_ENV=prod
Are you sure you want to install "phx_new-1.6.15.ez"? [Yn] y
* creating /home/ore/.mix/archives/phx_new-1.6.15

$ mix archive
* hex-2.0.6
* phx_new-1.6.15
Archives installed at: /home/ore/.mix/archives

手順

$ cd elixir

$ mix phx.new hello2
* creating hello2/config/config.exs
* creating hello2/config/dev.exs
* creating hello2/config/prod.exs
* creating hello2/config/runtime.exs
* creating hello2/config/test.exs
* creating hello2/lib/hello2/application.ex
* creating hello2/lib/hello2.ex
* creating hello2/lib/hello2_web/views/error_helpers.ex
* creating hello2/lib/hello2_web/views/error_view.ex
* creating hello2/lib/hello2_web/endpoint.ex
* creating hello2/lib/hello2_web/router.ex
* creating hello2/lib/hello2_web/telemetry.ex
* creating hello2/lib/hello2_web.ex
* creating hello2/mix.exs
* creating hello2/README.md
* creating hello2/.formatter.exs
* creating hello2/.gitignore
* creating hello2/test/support/conn_case.ex
* creating hello2/test/test_helper.exs
* creating hello2/test/hello2_web/views/error_view_test.exs
* creating hello2/lib/hello2/repo.ex
* creating hello2/priv/repo/migrations/.formatter.exs
* creating hello2/priv/repo/seeds.exs
* creating hello2/test/support/data_case.ex
* creating hello2/lib/hello2_web/controllers/page_controller.ex
* creating hello2/lib/hello2_web/views/page_view.ex
* creating hello2/test/hello2_web/controllers/page_controller_test.exs
* creating hello2/test/hello2_web/views/page_view_test.exs
* creating hello2/assets/vendor/topbar.js
* creating hello2/lib/hello2_web/templates/layout/root.html.heex
* creating hello2/lib/hello2_web/templates/layout/app.html.heex
* creating hello2/lib/hello2_web/templates/layout/live.html.heex
* creating hello2/lib/hello2_web/views/layout_view.ex
* creating hello2/lib/hello2_web/templates/page/index.html.heex
* creating hello2/test/hello2_web/views/layout_view_test.exs
* creating hello2/lib/hello2/mailer.ex
* creating hello2/lib/hello2_web/gettext.ex
* creating hello2/priv/gettext/en/LC_MESSAGES/errors.po
* creating hello2/priv/gettext/errors.pot
* creating hello2/assets/css/phoenix.css
* creating hello2/assets/css/app.css
* creating hello2/assets/js/app.js
* creating hello2/priv/static/robots.txt
* creating hello2/priv/static/images/phoenix.png
* creating hello2/priv/static/favicon.ico

Fetch and install dependencies? [Yn] y
* running mix deps.get

We are almost there! The following steps are missing:

    $ cd hello2

Then configure your database in config/dev.exs and run:

    $ mix ecto.create

Start your Phoenix app with:

    $ mix phx.server

You can also run your app inside IEx (Interactive Elixir) as:

    $ iex -S mix phx.server


$ mix ecto.create
** (Mix) The task "ecto.create" could not be found
Note no mix.exs was found in the current directory

$ cd hello2

$ mix ecto.create
==> file_system
Compiling 7 files (.ex)
Generated file_system app
==> decimal
Compiling 4 files (.ex)
Generated decimal app
==> mime
Compiling 1 file (.ex)
Generated mime app
==> hello2
Could not find "rebar3", which is needed to build dependency :telemetry
I can install a local copy which is just used by Mix
Shall I install rebar3? (if running non-interactively, use "mix local.rebar --force") [Yn] y
* creating /home/ore/.mix/rebar
* creating /home/ore/.mix/rebar3
===> Analyzing applications...
===> Compiling telemetry
==> telemetry_metrics
Compiling 7 files (.ex)
Generated telemetry_metrics app
===> Analyzing applications...
===> Compiling telemetry_poller
==> jason
Compiling 10 files (.ex)
Generated jason app
==> db_connection
Compiling 15 files (.ex)
Generated db_connection app
==> expo
Compiling 2 files (.erl)
Compiling 21 files (.ex)
Generated expo app
==> phoenix_pubsub
Compiling 11 files (.ex)
Generated phoenix_pubsub app
==> plug_crypto
Compiling 5 files (.ex)
Generated plug_crypto app
==> gettext
Compiling 17 files (.ex)
Generated gettext app
===> Analyzing applications...
===> Compiling ranch
==> ecto
Compiling 56 files (.ex)
Generated ecto app
==> plug
Compiling 1 file (.erl)
Compiling 40 files (.ex)
Generated plug app
==> phoenix_html
Compiling 9 files (.ex)
Generated phoenix_html app
==> phoenix_template
Compiling 4 files (.ex)
Generated phoenix_template app
==> phoenix_view
Compiling 1 file (.ex)
Generated phoenix_view app
==> postgrex
Compiling 68 files (.ex)
Generated postgrex app
==> ecto_sql
Compiling 25 files (.ex)
Generated ecto_sql app
==> castore
Compiling 1 file (.ex)
Generated castore app
==> esbuild
Compiling 3 files (.ex)
Generated esbuild app
===> Analyzing applications...
===> Compiling cowlib
===> Analyzing applications...
===> Compiling cowboy
===> Analyzing applications...
===> Compiling cowboy_telemetry
==> plug_cowboy
Compiling 5 files (.ex)
Generated plug_cowboy app
==> phoenix
Compiling 69 files (.ex)
Generated phoenix app
==> phoenix_live_reload
Compiling 4 files (.ex)
Generated phoenix_live_reload app
==> phoenix_live_view
Compiling 31 files (.ex)
Generated phoenix_live_view app
==> phoenix_live_dashboard
Compiling 40 files (.ex)
Generated phoenix_live_dashboard app
==> swoosh
Compiling 44 files (.ex)
Generated swoosh app
==> phoenix_ecto
Compiling 7 files (.ex)
Generated phoenix_ecto app
warning: the :gettext compiler is no longer required in your mix.exs.

Please find the following line in your mix.exs and remove the :gettext entry:

    compilers: [..., :gettext, ...] ++ Mix.compilers(),

  (gettext 0.23.1) lib/mix/tasks/compile.gettext.ex:5: Mix.Tasks.Compile.Gettext.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:92: Mix.Tasks.Compile.All.run_compiler/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:72: Mix.Tasks.Compile.All.compile/4
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:59: Mix.Tasks.Compile.All.with_logger_app/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:36: Mix.Tasks.Compile.All.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (mix 1.13.4) lib/mix/tasks/compile.ex:131: Mix.Tasks.Compile.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (mix 1.13.4) lib/mix/tasks/app.config.ex:32: Mix.Tasks.App.Config.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (ecto 3.10.3) lib/mix/ecto.ex:70: Mix.Ecto.ensure_repo/2
  (ecto 3.10.3) lib/mix/tasks/ecto.create.ex:50: anonymous fn/3 in Mix.Tasks.Ecto.Create.run/1
  (elixir 1.13.4) lib/enum.ex:937: Enum."-each/2-lists^foreach/1-0-"/2
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (mix 1.13.4) lib/mix/cli.ex:84: Mix.CLI.run_task/2
  (elixir 1.13.4) src/elixir_compiler.erl:73: :elixir_compiler.dispatch/4
  (elixir 1.13.4) src/elixir_compiler.erl:58: :elixir_compiler.compile/3

==> hello2
Compiling 14 files (.ex)
Generated hello2 app

09:55:09.148 [error] Postgrex.Protocol (#PID<0.5263.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused

09:55:09.174 [error] Postgrex.Protocol (#PID<0.5267.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
** (Mix) The database for Hello2.Repo couldn't be created: killed


$ sudo service postgresql start
[sudo] password for ore:
 * Starting PostgreSQL 10 database server                                                                        [ OK ]

$ mix ecto.create
warning: the :gettext compiler is no longer required in your mix.exs.

Please find the following line in your mix.exs and remove the :gettext entry:

    compilers: [..., :gettext, ...] ++ Mix.compilers(),

  (gettext 0.23.1) lib/mix/tasks/compile.gettext.ex:5: Mix.Tasks.Compile.Gettext.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:92: Mix.Tasks.Compile.All.run_compiler/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:72: Mix.Tasks.Compile.All.compile/4
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:59: Mix.Tasks.Compile.All.with_logger_app/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:36: Mix.Tasks.Compile.All.run/1

The database for Hello2.Repo has been created

$ mix phx.server
warning: the :gettext compiler is no longer required in your mix.exs.

Please find the following line in your mix.exs and remove the :gettext entry:

    compilers: [..., :gettext, ...] ++ Mix.compilers(),

  (gettext 0.23.1) lib/mix/tasks/compile.gettext.ex:5: Mix.Tasks.Compile.Gettext.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:92: Mix.Tasks.Compile.All.run_compiler/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:72: Mix.Tasks.Compile.All.compile/4
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:59: Mix.Tasks.Compile.All.with_logger_app/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:36: Mix.Tasks.Compile.All.run/1

[error] `inotify-tools` is needed to run `file_system` for your system, check https://github.com/rvoicilas/inotify-tools/wiki for more information about how to install it. If it's already installed but not be found, appoint executable file with `config.exs` or `FILESYSTEM_FSINOTIFY_EXECUTABLE_FILE` env.
[warning] Could not start Phoenix live-reload because we cannot listen to the file system.
You don't need to worry! This is an optional feature used during development to
refresh your browser when you save files and it does not affect production.

[info] Running Hello2Web.Endpoint with cowboy 2.10.0 at 127.0.0.1:4000 (http)
[debug] Downloading esbuild from https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.29.tgz
[info] Access Hello2Web.Endpoint at http://localhost:4000
[watch] build finished, watching for changes...
warning: the :gettext compiler is no longer required in your mix.exs.

Please find the following line in your mix.exs and remove the :gettext entry:

    compilers: [..., :gettext, ...] ++ Mix.compilers(),

  (gettext 0.23.1) lib/mix/tasks/compile.gettext.ex:5: Mix.Tasks.Compile.Gettext.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
  (phoenix 1.6.16) lib/phoenix/code_reloader/server.ex:249: Phoenix.CodeReloader.Server.mix_compile/2
  (phoenix 1.6.16) lib/phoenix/code_reloader/server.ex:178: Phoenix.CodeReloader.Server.mix_compile/4
  (phoenix 1.6.16) lib/phoenix/code_reloader/server.ex:73: anonymous fn/3 in Phoenix.CodeReloader.Server.handle_call/3
  (phoenix 1.6.16) lib/phoenix/code_reloader/server.ex:286: Phoenix.CodeReloader.Server.proxy_io/1
  (phoenix 1.6.16) lib/phoenix/code_reloader/server.ex:71: Phoenix.CodeReloader.Server.handle_call/3
  (stdlib 4.3) gen_server.erl:1149: :gen_server.try_handle_call/4
  (stdlib 4.3) gen_server.erl:1178: :gen_server.handle_msg/6
  (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

[info] GET /
[debug] Processing with Hello2Web.PageController.index/2
  Parameters: %{}
  Pipelines: [:browser]
[info] Sent 200 in 153ms
warning: the :gettext compiler is no longer required in your mix.exs.

Please find the following line in your mix.exs and remove the :gettext entry:

    compilers: [..., :gettext, ...] ++ Mix.compilers(),

  (gettext 0.23.1) lib/mix/tasks/compile.gettext.ex:5: Mix.Tasks.Compile.Gettext.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
  (phoenix 1.6.16) lib/phoenix/code_reloader/server.ex:249: Phoenix.CodeReloader.Server.mix_compile/2
  (phoenix 1.6.16) lib/phoenix/code_reloader/server.ex:178: Phoenix.CodeReloader.Server.mix_compile/4
  (phoenix 1.6.16) lib/phoenix/code_reloader/server.ex:73: anonymous fn/3 in Phoenix.CodeReloader.Server.handle_call/3
  (phoenix 1.6.16) lib/phoenix/code_reloader/server.ex:286: Phoenix.CodeReloader.Server.proxy_io/1
  (phoenix 1.6.16) lib/phoenix/code_reloader/server.ex:71: Phoenix.CodeReloader.Server.handle_call/3
  (stdlib 4.3) gen_server.erl:1149: :gen_server.try_handle_call/4
  (stdlib 4.3) gen_server.erl:1178: :gen_server.handle_msg/6
  (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3








写真

image.png

image.png

image.png

以上。

1
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
1
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?